DataTables("SQL_wdjbxxb").Load
Dim w_type As String
w_type = e.Form.Controls("ComboBox1").value
Dim dr As DataRow = Tables("SQL_wdjbxxb").Current.DataRow
If dr.RowState = DataRowState.Added Then '如果是新增行,必须先保存才能插入文件
dr.Save()
End If
Dim dlg As New OpenFileDialog
dlg.Filter="所有文件|*.*" '设置筛选器
Dim ex As String
If dlg.ShowDialog =DialogResult.OK Then
Dim fl As String = dlg.FileName
' Dim ex As String
ex = fl.SubString(fl.LastIndexOf(".") + 1) '获取文件后缀名
ex = ex & "|" & CRCCheckFile(fl) '将后缀名和文件的crc校验值组合成一个字符串
dr.SQLInsertFile("image",fl) '插入文件
dr.SQLSetValue("kzm",ex) '将文件的后缀名和crc校验值保存在信息列
End If
msgbox(dlg.FileName)
Dim lujing = dlg.FileName
Dim ifo As new FileInfo(lujing)
Dim w_CreationTime As String
Dim w_LastWriteTime As String
Dim w_LastAccessTime As String
Dim w_ReadOnly As String
Dim w_Hidden As String
Dim w_Path As String
Dim w_Length As Double
Dim w_Name As String
'Dim w_Extension As String
w_CreationTime = ifo.CreationTime
w_LastWriteTime = ifo.LastWriteTime
w_LastAccessTime = ifo.LastAccessTime
w_ReadOnly = ifo.ReadOnly
w_Hidden = ifo.Hidden
w_Path = ifo.Path
w_Length = ifo.Length
w_Name = ifo.Name
' w_Extension = ifo.Extension
Dim User1 As String = _UserName
Dim User2 As String = _UserName
Dim W_L As String
Select Case w_Length
Case Is <1048576
W_L =format(w_Length/1024,"0.00")& "KB"
Case Is < 1073741824
W_L =format(w_Length/1048576,"0.00")& "MB"
Case Else
W_L =format(w_Length/1073741824,"0.00")& "GB"
End Select
Dim fs As New IO.FileStream(lujing , IO.FileMode.Open , IO.FileAccess.Read) '用文件流打开图片
Dim br As New IO.BinaryReader(fs) '根据文件流,申明一个二进制阅读器
Dim ImageByte() As Byte = br.ReadBytes(fs.Length) '阅读器读取文件流,并将独到的二进制放入数组ImageByte中,
Dim ImageString As String = BitConverter.ToString(imageByte).Replace("-", "") ' SQLCommand 不能直接Insert 二进制,只能拼接SQL语句,所以这里把二进制变成字符
Dim cmd As New SQLCommand
cmd.C
'cmd.CommandText = "Insert Into {wdjbxxb} ([wdmc],[wdlx],[wddx],[wdcjr],[cjsj],[wdxgr],[xgsj]) Values ('"
'cmd.CommandText = cmd.CommandText & w_Name & "','" & w_type & "','" & W_L & "','" & User1 & "','" & w_CreationTime & "','" & User2 & "','" & w_LastWriteTime & "')"
'cmd.ExecuteNonQuery
cmd.CommandText = "Insert Into {wdjbxxb} ([wdmc],[wdlx],[wddx],[wdcjr],[cjsj],[wdxgr],[xgsj],[image],[kzm]) Values ('"
cmd.CommandText = cmd.CommandText & w_Name & "','" & w_type & "','" & W_L & "','" & User1 & "','" & w_CreationTime & "','" & User2 & "','" & w_LastWriteTime & "',0x" + ImageString + ",'" & ex & "')"
cmd.ExecuteNonQuery
DataTables("SQL_wdjbxxb").Save()
Tables("SQL_wdjbxxb").Current.Load()
'Messagebox.show(w_type)
Forms("文档类型选择窗口").Close()
Forms("文档权限设置").Open()
老师,这段代码报错:未将对象引用设置到对象的实例。我找不到地方?
请老师检查一下。