| Подскажите пж. как добавить картинку в БД в существующую запись. Во вновь создаваемую запись умею. Делаю так: 
 Dim strBLOBFilePath As String
 
 Dim fsimgFile As New FileStream(cover, FileMode.Open, FileAccess.Read)
 strBLOBFilePath = cover
 
 
 If Not (fsimgFile Is Nothing) Then
 
 'Создаем FileStream из существующего файла.
 Dim fi As New FileInfo(CoverPath_RTB.Text)
 Dim fs As FileStream = fi.OpenRead()
 
 'Читаем bytes в массив из существующего файла.
 Dim nBytes As Integer = fi.Length
 Dim ByteArray(nBytes) As Byte
 Dim nBytesRead As Integer = fs.Read(ByteArray, 0, nBytes)
 
 Dim s As New MemoryStream(nBytes)
 count = 0
 While (count < nBytes)
 s.WriteByte(ByteArray(count))
 count += 1
 End While
 s.Position = 0
 End If
 
 
 command = New OleDbCommand("INSERT INTO " & DtS.Tables(0).Rows(0).Item("tbl_nm") & " (nm, dislok, dName, fName, pict)" & _
 " VALUES ('" & nm & "', '" & dislok & "', '" & dName & "', '" & fName & "', '" & dtaa & "', @BLOBData)", connection)
 
 If Not (fsimgFile Is Nothing) Then
 Dim bytBLOBData(fsimgFile.Length() - 1) As Byte
 fsimgFile.Read(bytBLOBData, 0, bytBLOBData.Length)
 fsimgFile.Close()
 Dim prm As New OleDbParameter("@BLOBData", OleDbType.VarBinary, _
 bytBLOBData.Length, ParameterDirection.Input, False, _
 0, 0, Nothing, DataRowVersion.Current, bytBLOBData)
 command.Parameters.Add(prm)
 End If
 
 DtA1.InsertCommand = command
 DtS1.Tables(0).Rows.Add()
 
 str1 = "UPDATE " & DtS.Tables(0).Rows(0).Item("tbl_nm")
 command = New OleDbCommand(str1, connection)
 DtA1.UpdateCommand = command
 DtA1.Update(DtS1)
 
 но если строка уже есть и часть информации уже введена то добавить картинку не умею (не удалив строку и добавив новую).
 
 делал (пытался) так
 Dim DtV1 As New DataView
 DtV1.Table = DtS1.Tables(0)
 DtV1(0)("nm") = nm
 DtV1(0)("dislok") = dislok
 DtV1(0)("dName") = dName
 DtV1(0)("fName") = fName
 DtV1(0)("author") = author
 DtV1(0)("roles") = roles
 DtV1(0)("dta") = dtaa
 DtV1(0)("pict") = ByteArray
 
 
 End If
 
 If Not (fsimgFile Is Nothing) Then
 Dim bytBLOBData(fsimgFile.Length() - 1) As Byte
 fsimgFile.Read(bytBLOBData, 0, bytBLOBData.Length)
 fsimgFile.Close()
 Dim prm As New OleDbParameter("@BLOBData", OleDbType.VarBinary, _
 bytBLOBData.Length, ParameterDirection.Input, False, _
 0, 0, Nothing, DataRowVersion.Current, bytBLOBData)
 command.Parameters.Add(prm)
 
 str1 = "UPDATE " & DtS.Tables(0).Rows(0).Item("tbl_nm") & " SET nm='" & nm & "', dislok='" & dislok & "', dName='" & dName & "', fName='" & fName & "', pict=@BLOBData WHERE cod=" & Me.cod_TB.Text
 End If
 command = New OleDbCommand(str1, connection)
 DtA1.UpdateCommand = command
 DtA1.Update(DtS1)
 
 чему должно ровняться "pict" не пойму
 
 Киньте пж пример.
 Ответить
       |