hi,
i looking for a easy way to save a image to a sql server i
have found a lot of examples but many is for asp.net and others have
many functions for do a simple process that with vb6 i do with a few lines:
"mstream.LoadFromFile .FileName
RS.Fields("imagem_sql").Value = mstream.Read
Image1.Picture = LoadPicture(.FileName)
RS.update"
so i looking for a simple way to do that i have found this:
connetionString = "Data Source=ip;Initial Catalog=bd;User ID=user;Password=pass"
Dim con As String = connetionString
Dim str As String = "select * from store where id like '" & TextBox23.Text & "'"
Dim da As New SqlDataAdapter(str, con)
Dim cmd As New SqlCommand(str, New SqlConnection(con))
Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
Dim ds As New DataSet()
connection.Open()
command = New SqlCommand(sql, connection)
adapter.SelectCommand = command
adapter.Fill(ds)
adapter.Dispose()
command.Dispose()
connection.Close()
Dim fs As New FileStream(txtImageFile.Text, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite)
Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
ds.Tables(0).Rows(0)("imagem_sql") = MyData
da.Update(ds, 0)
fs = Nothing
MyCB = Nothing
ds = Nothing
da = Nothing
cmd.Connection.Close()
con = Nothing
but this simple dont update nothing
i have tryed to update a text value but the result is the same nothing is updated!
but he actully dont return any error and i can see that the record is opened but simple can´t update
any one can help me to understand what is wrong and why this dont update?
thanks a lot for your help
i looking for a easy way to save a image to a sql server i
have found a lot of examples but many is for asp.net and others have
many functions for do a simple process that with vb6 i do with a few lines:
"mstream.LoadFromFile .FileName
RS.Fields("imagem_sql").Value = mstream.Read
Image1.Picture = LoadPicture(.FileName)
RS.update"
so i looking for a simple way to do that i have found this:
connetionString = "Data Source=ip;Initial Catalog=bd;User ID=user;Password=pass"
Dim con As String = connetionString
Dim str As String = "select * from store where id like '" & TextBox23.Text & "'"
Dim da As New SqlDataAdapter(str, con)
Dim cmd As New SqlCommand(str, New SqlConnection(con))
Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
Dim ds As New DataSet()
connection.Open()
command = New SqlCommand(sql, connection)
adapter.SelectCommand = command
adapter.Fill(ds)
adapter.Dispose()
command.Dispose()
connection.Close()
Dim fs As New FileStream(txtImageFile.Text, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite)
Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
ds.Tables(0).Rows(0)("imagem_sql") = MyData
da.Update(ds, 0)
fs = Nothing
MyCB = Nothing
ds = Nothing
da = Nothing
cmd.Connection.Close()
con = Nothing
but this simple dont update nothing
i have tryed to update a text value but the result is the same nothing is updated!
but he actully dont return any error and i can see that the record is opened but simple can´t update
any one can help me to understand what is wrong and why this dont update?
thanks a lot for your help
