S
Scott
Unfortunately the autogenerated code does not refresh the data of the
inserted id column despite checking off "refresh data" and creating an
output parameter with mySQL. It does work with SQL Server though. In
this case I am working with MySQL though.
So I googled and googled and found (in theory) one could add an event
handler to the dataadapter that the tableadapter uses for the
rowupdated event and then fire off the subsequent query select
last_insert_id and update the identity value in the datarow.
No matter what I do however, I cannot seem to intercept the rowupdated
event. In some of the first examples these people were simply
creating a sub with the handles _adapter.RowUpdated and saying that
worked. This did not work, however for me. Searching even more I
found some people using the addhandler to add the event manually.
I also wanted to add the event handler into the instantiation of the
dataset object but I could not figure out where to put the code to
make that work. Instead I created a public function I could call from
my component class.
Can anyone throw me a bone here? Why does programming with MySQL
always have to be some damn difficult?
Here is the latest permutation of the code I am working with.
Namespace VTDSTableAdapters
Partial Public Class taCscart_products
Private IdentityQuery As New
MySql.Data.MySqlClient.MySqlCommand("SELECT LAST_INSERT_ID()",
Nothing)
Private Sub _adapter_RowUpdated(ByVal sender As Object, ByVal
e As MySql.Data.MySqlClient.MySqlRowUpdatedEventArgs) Handles
_adapter.RowUpdated
If e.StatementType = StatementType.Insert AndAlso _
e.Status = UpdateStatus.Continue Then
IdentityQuery.Connection = e.Command.Connection
e.Row("Product_Id") = IdentityQuery.ExecuteScalar
End If
End Sub
Public Sub AddHandlers()
InitConnection()
InitCommandCollection()
InitAdapter()
AddHandler _adapter.RowUpdated, AddressOf
_adapter_RowUpdated
End Sub
End Class
End Namespace
inserted id column despite checking off "refresh data" and creating an
output parameter with mySQL. It does work with SQL Server though. In
this case I am working with MySQL though.
So I googled and googled and found (in theory) one could add an event
handler to the dataadapter that the tableadapter uses for the
rowupdated event and then fire off the subsequent query select
last_insert_id and update the identity value in the datarow.
No matter what I do however, I cannot seem to intercept the rowupdated
event. In some of the first examples these people were simply
creating a sub with the handles _adapter.RowUpdated and saying that
worked. This did not work, however for me. Searching even more I
found some people using the addhandler to add the event manually.
I also wanted to add the event handler into the instantiation of the
dataset object but I could not figure out where to put the code to
make that work. Instead I created a public function I could call from
my component class.
Can anyone throw me a bone here? Why does programming with MySQL
always have to be some damn difficult?
Here is the latest permutation of the code I am working with.
Namespace VTDSTableAdapters
Partial Public Class taCscart_products
Private IdentityQuery As New
MySql.Data.MySqlClient.MySqlCommand("SELECT LAST_INSERT_ID()",
Nothing)
Private Sub _adapter_RowUpdated(ByVal sender As Object, ByVal
e As MySql.Data.MySqlClient.MySqlRowUpdatedEventArgs) Handles
_adapter.RowUpdated
If e.StatementType = StatementType.Insert AndAlso _
e.Status = UpdateStatus.Continue Then
IdentityQuery.Connection = e.Command.Connection
e.Row("Product_Id") = IdentityQuery.ExecuteScalar
End If
End Sub
Public Sub AddHandlers()
InitConnection()
InitCommandCollection()
InitAdapter()
AddHandler _adapter.RowUpdated, AddressOf
_adapter_RowUpdated
End Sub
End Class
End Namespace