Not updating

Not updating

Postby nickwood » Wed 17 Aug 2005 23:06

Hi All

I have just start using these components and like what I see so far.

I have an issue at this stage where I cant get a datagrid to update the database table. I have the following code:

Code: Select all
Public Sub UseDataAdapter(ByVal myConnection1 As MySqlConnection)
        Dim myAdapter As MySqlDataAdapter = New MySqlDataAdapter("SELECT game_id, sports_center_id FROM game", MySqlConnection1)
        myAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
        Dim myDataSet As DataSet = New DataSet()
        myAdapter.Fill(myDataSet, "Games")

        Dim myCommandBuilder As MySqlCommandBuilder = New MySqlCommandBuilder(myAdapter)

        myAdapter.UpdateCommand = New MySqlCommand("UPDATE game SET sports_center_id = :sports_center_id " & _
                "WHERE game_id = :oldgame_id", MySqlConnection1)
        myAdapter.UpdateCommand.Parameters.Add("game_id", MySqlType.Int, 15, "game_id")
        myAdapter.UpdateCommand.Parameters.Add("sports_center_id", MySqlType.Int, 15, "sports_center_id")
        myAdapter.UpdateCommand.Parameters.Add("oldgame_id", MySqlType.Int, 15, "game_id").SourceVersion = DataRowVersion.Original
        myAdapter.Update(myDataSet, "Games")

        game_info_DataGrid.DataSource = myDataSet.Tables(0).DefaultView

    End Sub


It loads the information into datagrid just fine, but no updating.

Can anyone please help?
nickwood
 

Postby Serious » Thu 18 Aug 2005 06:52

You don't have to create Insert, Update, Delete commands when using MySqlCommandBuilder.
Try this:
Code: Select all
Public Sub UseDataAdapter(ByVal myConnection1 As MySqlConnection)
        Dim myAdapter As MySqlDataAdapter = New MySqlDataAdapter("SELECT game_id, sports_center_id FROM game", MySqlConnection1)
        myAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
        Dim myCommandBuilder As MySqlCommandBuilder = New MySqlCommandBuilder(myAdapter)
        Dim myDataSet As DataSet = New DataSet()
        myAdapter.Fill(myDataSet, "Games")
        game_info_DataGrid.DataSource = myDataSet.Tables(0).DefaultView
End Sub
Serious
 


Return to dotConnect for MySQL