alexatsearidge
asked on
Updating a database using a datagrid
Hello,
I am using C# 1.1 and I have an app with a datagrid that is bound to a dataset.
I want the user to be able to alter the contents of the grid and click a button to update the database with the new data.
Is it necessary to define Update/Insert commands? Or can I do something simple like:
dataAdapter.Update(dataSet .GetChange s());
dataSet.AcceptChanges();
I am using C# 1.1 and I have an app with a datagrid that is bound to a dataset.
I want the user to be able to alter the contents of the grid and click a button to update the database with the new data.
Is it necessary to define Update/Insert commands? Or can I do something simple like:
dataAdapter.Update(dataSet
dataSet.AcceptChanges();
ASKER
nvm I got it. How do I get a point refund?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the post but I think I'll stick with my soultion. Luckily I discovered the command builder so I do not have to deal with creating the Insert/Update/Delete commands
-------------------
// Create the DataSet
dsCDAConfig = new DataSet("RecordsFromProced ure");
// Define the stored procedure that will populate the dataset
OleDbCommand command= new OleDbCommand("pGetWhatever ", conn);
command.CommandType = CommandType.StoredProcedur e;
// Fill the Dataset with the return of the stored procedure
dataAdapter= new OleDbDataAdapter(command);
OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(dataAd apter);
dataAdapter.Fill(dataSet);
// We want to return the view of the recordset
DataView dataView = dataSet.Tables[0].DefaultV iew;
-------- Since the command builder handles the update command I can do the following later
DataSet updatedDataSet = dsCDAConfig.GetChanges();
if (updatedDataSet == null)
{
// nothing to update so we return
return;
}
dataAdapter.Update(updated DataSet); // The command builder creates the update command for me
dataAdapter.AcceptChanges( );
-------------------
// Create the DataSet
dsCDAConfig = new DataSet("RecordsFromProced
// Define the stored procedure that will populate the dataset
OleDbCommand command= new OleDbCommand("pGetWhatever
command.CommandType = CommandType.StoredProcedur
// Fill the Dataset with the return of the stored procedure
dataAdapter= new OleDbDataAdapter(command);
OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(dataAd
dataAdapter.Fill(dataSet);
// We want to return the view of the recordset
DataView dataView = dataSet.Tables[0].DefaultV
-------- Since the command builder handles the update command I can do the following later
DataSet updatedDataSet = dsCDAConfig.GetChanges();
if (updatedDataSet == null)
{
// nothing to update so we return
return;
}
dataAdapter.Update(updated
dataAdapter.AcceptChanges(
ASKER
Not exactly sure how to do that.
Also, I have about 10 different tables that this datagrid will display data for. It depends what the user selects in a list box.
Does this mean that I have to have 10 different data adapaters and 10 sets of insert/update/delete commands?