alreadyused
Well-known member
- Joined
- Jan 13, 2006
- Messages
- 70
Im stupmed; Im trying to use MySQL 5 w/ DataSets and VB.Net 2003, and am to the point where Im ready to update the database.
Im reading the Microsoft Press ADO.NET book by David Scheppa (starting on pg 408 if that helps anyone); Ive also looked at the example by Mike Hillyer here:
http://www.vbmysql.com/articles/vb_mysql_tutorial-part4.html#part14
that uses user input from textboxes.
What Im trying to do is write the generic update routines so I can pass it a row that has changed and have those changes sent to the db, assuming that I have already taken care of changing the row in the datatable. Heres my code, which is basically what is in the book...
[VB]
Public Sub SubmitChangesByHand(ByVal tbl As DataTable)
Dim cmdUpdate As MySqlCommand = CreateUpdateCommand()
Dim cmdInsert As MySqlCommand = CreateInsertCommand()
Dim cmdDelete As MySqlCommand = CreateDeleteCommand
Dim row As DataRow
Dim intRows As Integer
Dim dvrs As DataViewRowState
dvrs = DataViewRowState.ModifiedCurrent Or DataViewRowState.Deleted Or DataViewRowState.Added
For Each row In tbl.Select("", "", dvrs)
Select Case row.RowState
Case DataRowState.Modified
intRows = SubmitUpdate(row, cmdUpdate)
Case DataRowState.Added
intRows = SubmitInsert(row, cmdInsert)
Case DataRowState.Deleted
intRows = SubmitDelete(row, cmdDelete)
End Select
If intRows = 1 Then
row.AcceptChanges()
Else
row.RowError = "Update attempt failed"
End If
Next
End Sub
Private Function CreateInsertCommand() As MySqlCommand
Dim strSQL As String
strSQL = "INSERT INTO [vendorparts] " & _
"(intJobSerial, intUnitSerial, intRevSerial, dblSection, dblPartSerial) " & _
"VALUES (?intJobSerial, ?intUnitSerial, ?intRevSerial, ?dblSection, ?dblPartSerial)"
Dim cmd As New MySqlCommand(strSQL, _cn)
Dim pc As MySqlParameterCollection = cmd.Parameters
pc.Add("?intJobSerial", MySqlDbType.UInt32)
pc.Add("?intUnitSerial", MySqlDbType.UInt32)
pc.Add("?intRevSerial", MySqlDbType.UInt32)
pc.Add("?dblSection", MySqlDbType.Double)
pc.Add("?dblPartSerial", MySqlDbType.Double)
pc.Add("?strAssy", MySqlDbType.String)
Return cmd
End Function
Private Function SubmitInsert(ByVal row As DataRow, ByVal cmd As MySqlCommand) As Integer
Dim pc As MySqlParameterCollection = cmd.Parameters
pc("?intJobSerial").Value = row("intJobSerial")
pc("?intUnitSerial").Value = row("intUnitSerial")
pc("?intRevSerial").Value = row("intRevSerial")
pc("?dblSection").Value = row("dblSection")
pc("?dblPartSerial").Value = row("dblPartSerial")
pc("?strAssy").Value = row("strAssy")
Return cmd.ExecuteNonQuery
End Function
[/VB]
On
Return cmd.ExecuteNonQuery
in SubmitInsert, the error thrown is:
I have no clue where to even go to look for what I need to do here. Any suggestions anyone? My first thought is I have to change either the data types Im sending or use something other than MySQLBinary for serializing, but thats all new to me... is that the right direction?
Im reading the Microsoft Press ADO.NET book by David Scheppa (starting on pg 408 if that helps anyone); Ive also looked at the example by Mike Hillyer here:
http://www.vbmysql.com/articles/vb_mysql_tutorial-part4.html#part14
that uses user input from textboxes.
What Im trying to do is write the generic update routines so I can pass it a row that has changed and have those changes sent to the db, assuming that I have already taken care of changing the row in the datatable. Heres my code, which is basically what is in the book...
[VB]
Public Sub SubmitChangesByHand(ByVal tbl As DataTable)
Dim cmdUpdate As MySqlCommand = CreateUpdateCommand()
Dim cmdInsert As MySqlCommand = CreateInsertCommand()
Dim cmdDelete As MySqlCommand = CreateDeleteCommand
Dim row As DataRow
Dim intRows As Integer
Dim dvrs As DataViewRowState
dvrs = DataViewRowState.ModifiedCurrent Or DataViewRowState.Deleted Or DataViewRowState.Added
For Each row In tbl.Select("", "", dvrs)
Select Case row.RowState
Case DataRowState.Modified
intRows = SubmitUpdate(row, cmdUpdate)
Case DataRowState.Added
intRows = SubmitInsert(row, cmdInsert)
Case DataRowState.Deleted
intRows = SubmitDelete(row, cmdDelete)
End Select
If intRows = 1 Then
row.AcceptChanges()
Else
row.RowError = "Update attempt failed"
End If
Next
End Sub
Private Function CreateInsertCommand() As MySqlCommand
Dim strSQL As String
strSQL = "INSERT INTO [vendorparts] " & _
"(intJobSerial, intUnitSerial, intRevSerial, dblSection, dblPartSerial) " & _
"VALUES (?intJobSerial, ?intUnitSerial, ?intRevSerial, ?dblSection, ?dblPartSerial)"
Dim cmd As New MySqlCommand(strSQL, _cn)
Dim pc As MySqlParameterCollection = cmd.Parameters
pc.Add("?intJobSerial", MySqlDbType.UInt32)
pc.Add("?intUnitSerial", MySqlDbType.UInt32)
pc.Add("?intRevSerial", MySqlDbType.UInt32)
pc.Add("?dblSection", MySqlDbType.Double)
pc.Add("?dblPartSerial", MySqlDbType.Double)
pc.Add("?strAssy", MySqlDbType.String)
Return cmd
End Function
Private Function SubmitInsert(ByVal row As DataRow, ByVal cmd As MySqlCommand) As Integer
Dim pc As MySqlParameterCollection = cmd.Parameters
pc("?intJobSerial").Value = row("intJobSerial")
pc("?intUnitSerial").Value = row("intUnitSerial")
pc("?intRevSerial").Value = row("intRevSerial")
pc("?dblSection").Value = row("dblSection")
pc("?dblPartSerial").Value = row("dblPartSerial")
pc("?strAssy").Value = row("strAssy")
Return cmd.ExecuteNonQuery
End Function
[/VB]
On
Return cmd.ExecuteNonQuery
in SubmitInsert, the error thrown is:
Only byte arrays and strings can be serialized by MySQLBinary
...
I have no clue where to even go to look for what I need to do here. Any suggestions anyone? My first thought is I have to change either the data types Im sending or use something other than MySQLBinary for serializing, but thats all new to me... is that the right direction?