468,290 Members | 2,034 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

Unable to update datasource

Hello there.

I have the following code to enter data into a dataset and subsequently save the data to a SQL Server database. A datagrid attached to the dataset shows the added data when the 'Save' button is clicked. But when I check the database no record is added. Can anyone help with that please??

Con.Open();
string name = TxtName2.Text.Trim();
string address = TxtAdd2.Text.Trim();
string phNo = TxtPhNo2.Text.Trim();

SqlDataAdapter DaMembers2 = new SqlDataAdapter("Select * from Members", Con);
DataSet dsMembers2 = new DataSet();
DataTable dtMembers2 = new DataTable();

DaMembers2.Fill(dsMembers2, "dtMembers2");
SqlCommandBuilder CbMembers = new SqlCommandBuilder( DaMembers2 );

//Datagrid
dgMembers.DataSource = dsMembers2.Tables["dtMembers2"];
DataRow insertRow = dsMembers2.Tables["DtMembers2"].NewRow();

insertRow["Mem_Name"] = name;
insertRow["Mem_Address"] = address;
insertRow["Mem_PhNo"] = phNo;

dsMembers2.Tables["DtMembers2"].Rows.Add(insertRow);
dsMembers2.AcceptChanges();

DaMembers2.Update(dsMembers2, "dtMembers2");


dgMembers.Refresh();
Con.Close();
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
Nov 23 '06 #1
0 800

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Kevin Pedersen | last post: by
4 posts views Thread by René Kabis | last post: by
6 posts views Thread by Greg P | last post: by
4 posts views Thread by Arne Beruldsen | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.