今天按照网上试写了一个 如下 发现 可以插入到数据库里 但是 img2这个字段 插入的值是错误的,正确的应该是 很长一段 不知道问题出在那里 ,感觉插入img2字段不是byte类型或是bitmap类型
Dim sqlConnection1 As New SqlConnection(ZFC)
sqlConnection1.Open()
'*******************************
Dim fs As MemoryStream = New MemoryStream()
Dim Data(fs.Length) As Byte
fs.Read(Data, 0, Int(fs.Length))
Dim Sql As String
Sql = "SELECT * FROM [IMG]"
Dim cmd As New SqlClient.SqlCommand(Sql, sqlConnection1)
= "Insert Into [IMG] (ID,img_1,img_2) Values (@IDcard,null,@photo)"
' cmd.Connection = sqlConnection1
Dim prm1 As New SqlParameter("@IDcard", Me.Label7.Text)
Dim prm2 As New SqlParameter("@photo", SqlDbType.VarBinary, Int(fs.Length), ParameterDirection.Input, False, 0, 0, "", DataRowVersion.Current, Data)
cmd.Parameters.Add(prm1)
cmd.Parameters.Add(prm2)
cmd.ExecuteNonQuery()
MsgBox("添加照片成功!")
fs.Dispose()
'***********************************
sqlConnection1.Close()
[此贴子已经被作者于2020-9-29 22:55编辑过]