0

I use:
Visual studio 8.0
MySql database
One table:
table :Groups, two fields : groupnb,groupdef
One Datagridview with is link to Mydataset1

Some times a get this MySQL error:

"Connection must be valid and open"

I use first this command :

MyDataset1.Tables("groups").Rows.InsertAt(row, 0)

Then I change the content of some fields in Datagridview1
Then i use this command, see code :

90% of the time goes well,i get no error

How can I avoid getting this error message!

If MyDataset1.GetChanges() Is Nothing Then
            MessageBox.Show("No record are changed")
        Else
            Dim rowsAffected As Integer = myAdapter1.Update(MyDataTable1)
            If rowsAffected = 0 Then
                MessageBox.Show("No record are changed")
            Else
                MessageBox.Show(rowsAffected & " Records are changed")
            End If
End If
2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by dre-logics
0

Check your Command. You should pass the Connection as an argument. It should look like this:

x = new Command("Select * From x", Connection);

Thanks

0

Check your Command. You should pass the Connection as an argument. It should look like this:

x = new Command("Select * From x", Connection);

Thanks

No, thats not the problem!!,thanks anyway
I know exactly when the problem occurs!
I now use this code ,exactly in this order
The error message only occurs when I first edit- or delete records and then add a record.
I do it the other way (I first add a record and than edit or delete records) I get no error messages.

myAdapter1.Update(MyDataTable1.Select(Nothing, Nothing, DataViewRowState.Deleted))
myAdapter1.Update(MyDataTable1.Select(Nothing, Nothing, DataViewRowState.ModifiedCurrent))
myAdapter1.Update(MyDataTable1.Select(Nothing, Nothing, DataViewRowState.Added))
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.