470,855 Members | 2,806 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 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??

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 );

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

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


DaMembers2.Update(dsMembers2, "dtMembers2");

catch(Exception e)
Nov 23 '06 #1
0 841

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
By using this site, you agree to our Privacy Policy and Terms of Use.