I have a main Form. There is a linklabel. If i click on it, a new form will open, and there is a datagrid and a button on it. The datagrid will be filled with data on the new forms Load event.
I bind the datasource this way:
void BindDataSource( BindingSource^ BS, SqlDataAdapter^ DA, DataGridView^ DG, String^ SQLCommand )
{
DG->DataSource = BS;
//InsertDataToDataGrid( "select * from myTable", dataGridView10 );
String^ connectionString = "database=myDataBase;server=myServer;UID=UserID;PWD=Password;";
// Create a new data adapter based on the specified query.
DA = gcnew SqlDataAdapter( SQLCommand, connectionString);
gcnew SqlCommandBuilder( DA );
DataTable^ table = gcnew DataTable();
DA->Fill( table );
BS->DataSource = table;
}//BindDataSource
If i click the button it should save the changes.
I save it like this:
dAPcExceptions->Update( ( DataTable^ )bSPCExceptions->DataSource );
I use this method on the main Form and it is working fine.
However if i click the button i get an error:
update requires a valid updatecommand when passed datarow collection with modified rows
Can someone tell me what i am doing wrong?
Thanks!
I suppose you area creating a SqlDataAdapter and returing it for future uses. So you must use a track reference to make SqlDataAdapter parameter as input/output.