Hello, I am trying to adapt MS code:
http://support.microsoft.com/default.aspx?scid=kb;en-us;308042
to store a picture in a mysql database. I keep getting this error:
An unhandled exception of type System.InvalidOperationException occurred in system.data.dll
Additional information: Update requires a valid InsertCommand when passed DataRow collection with new rows.
and it selects this line: "da.Update(ds, "MyImages")"
here is my code.
Any ideas?
I would definitly be up for diff code.. as I have to populate a database with tons of pictures.. and this code will take forever to upload all the pics
thanks guys!
http://support.microsoft.com/default.aspx?scid=kb;en-us;308042
to store a picture in a mysql database. I keep getting this error:
An unhandled exception of type System.InvalidOperationException occurred in system.data.dll
Additional information: Update requires a valid InsertCommand when passed DataRow collection with new rows.
and it selects this line: "da.Update(ds, "MyImages")"
here is my code.
Code:
Dim con As MySqlConnection
Dim connString As String = "Server=192.168.254.7;username=me;password=nopeeking;database=test;persist security info=true;compress=true;pooling=true"
con = New MySqlConnection(connString)
Dim MyCommand As String = "Select * From MyImages"
Dim da As New MySqlDataAdapter(MyCommand, con)
Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
Dim ds As New DataSet
da.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim fs As New FileStream("C:\windows\Gone Fishing.BMP", FileMode.OpenOrCreate, FileAccess.Read)
Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
con.Open()
da.Fill(ds, "MyImages")
Dim myRow As DataRow
myRow = ds.Tables("MyImages").NewRow()
myRow("Description") = "This would be description text"
myRow("imgField") = MyData
ds.Tables("MyImages").Rows.Add(myRow)
da.Update(ds, "MyImages")
fs = Nothing
MyCB = Nothing
ds = Nothing
da = Nothing
con.Close()
con = Nothing
MsgBox("Image saved to database")
Any ideas?
I would definitly be up for diff code.. as I have to populate a database with tons of pictures.. and this code will take forever to upload all the pics
thanks guys!