updating a dataset using a datagrid [*Resolved*]
Hello
I have a datagrid that is filled using the dataadapter. The datagrid that can be edited. Once the customer has completed the editing l want to update the new contents of the datagrid. This is what l have so far:
Code:
da.SelectCommand = cmd;
da.Fill(ds,"Product");
this.grdCustomerPurchase.SetDataBinding(ds,"Product");
//How would l update the dataset once the customer has edited the contents of the datagrid
Many thanks in advance,
Steve
Re: updating a dataset using a datagrid
You are Filling a DataTable using a DataAdapter and to get the deletions, insertions and updates back to the database you need to Update the same DataTable with, generally, the same DataAdapter. You have created the SelectCommand for your DataAdapter as evidenced by your code. You now have to create the corresponding DeleteCommand and/or InsertCommand and/or UpdateCommand to do the obvious and call Update on the DataAdapter. I suggest that you take a look at the help/MSDN topics for those properties for code examples. Also, all the tutorial links in my signature have a section on ADO.NET that will give you information and examples. The 101 samples also contain examples of data access operations.
1 Attachment(s)
Re: updating a dataset using a datagrid [*Resolved*]
Hi Guys,
I have looked everywhere, and I am almost there, but still cannot figure out how to properly update the Database. I following a SAMS C# book word to word (attached) and it doesn't have a suitable UpdateCommand --- which is very strange.
In my sample application, urlwizard.mdb is my database. tURL is the table. UserName, Password, Domain and Port are the four fields.
What I would like to know is a suitable UpdateCommand based on this information.
VB Code:
private void btnSave_Click(object sender, System.EventArgs e)
{
// If there is existing data, update it.
if (m_dtUsers.Rows.Count != 0)
{
m_dtUsers.Rows[m_rowPosition]["UserName"] = txtUserName.Text;
m_dtUsers.Rows[m_rowPosition]["Password"] = txtPassword.Text;
m_daDataAdapter.Update(m_dtUsers);
}
}
What would be the UpdateCommand for this database.
Thanks,
McoreD
Re: updating a dataset using a datagrid [*Resolved*]
This is so weird. You cannot have "Domain" as a column in an Access datbase, which is why I have been failing to Load and Update.
Re: updating a dataset using a datagrid [*Resolved*]
Quote:
Originally Posted by ~*McoreD*~
This is so weird. You cannot have "Domain" as a column in an Access datbase, which is why I have been failing to Load and Update.
It's not weird at all. You can use whatever name you want for columns but if you choose an Access or SQL reserved word then you need to enclose it in square brackets when you include it in commands. Otherwise it is interpreted as its reserved meaning and will almost certainly create a syntax error or, in very rare cases, execute but do something other than what you intended.