Update table bind to datagrid

I want to update the table that is bind to the datagrid through dataset.

her is what i am doing

private void FrmTemplateNew_Load(object sender, System.EventArgs e)
{
AsaCon= new SqlConnection("user id=sa;" +
      "password=sa;server=harbinger;" +
      "database=oct29_2004; " +
      "connection timeout=30");
AsaCon.Open();
AsaCmd=new SqlCommand("Select * from TblTemplate",AsaCon);
AsaDptr=new SqlDataAdapter(AsaCmd);
Dset=new DataSet("tblTemplate");
AsaDptr.Fill(Dset,"tblTemplate");
dataGrid1.SetDataBinding(Dset,"tblTemplate");
dataGrid1.DataSource=Dset;
}

private void button1_Click(object sender, System.EventArgs e)
{
Dset.AcceptChanges();//I used this becz without it the update was giving error that I
                                 //must specifiy a valid update statement
AsaDptr.Update(Dset,"tblTemplate");
}

Now it is not giving the error but is also not updatting the table.

Please help me out. Its urgent.

arvshaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

123654789987Commented:
U need to make some changes in the code

private void FrmTemplateNew_Load(object sender, System.EventArgs e)
{
AsaCon= new SqlConnection("user id=sa;" +
     "password=sa;server=harbinger;" +
     "database=oct29_2004; " +
     "connection timeout=30");
AsaCon.Open();
AsaCmd=new SqlCommand("Select * from TblTemplate",AsaCon);
SqlCommandBuilder custCB = new SqlCommandBuilder(AsaDptr); // A commandbuilder is required
AsaDptr=new SqlDataAdapter(AsaCmd);
Dset=new DataSet("tblTemplate");
AsaDptr.Fill(Dset,"tblTemplate");
dataGrid1.SetDataBinding(Dset,"tblTemplate");
dataGrid1.DataSource=Dset;
}

private void button1_Click(object sender, System.EventArgs e)
{
AsaDptr.Update(Dset,"tblTemplate");
}

0
arvshaAuthor Commented:
I tried it

private void FrmTemplateNew_Load(object sender, System.EventArgs e)
{
AsaCon= new SqlConnection("user id=sa;" +
      "password=sa;server=harbinger;" +
                "database=oct29_2004; " +
      "connection timeout=30");
AsaCon.Open();
AsaCmd=new SqlCommand("Select * from dt_Account",AsaCon);
custCB = new SqlCommandBuilder(AsaDptr); // A commandbuilder is required
AsaDptr=new SqlDataAdapter(AsaCmd);
Dset=new DataSet("dt_Account");
AsaDptr.Fill(Dset,"dt_Account");
dataGrid1.SetDataBinding(Dset,"dt_Account");
dataGrid1.DataSource=Dset.Tables["dt_Account"];
}
private void button1_Click(object sender, System.EventArgs e)
{
//dataGrid1.Update();
Dset.AcceptChanges(); //added this because without it the next stetement is generating error.
AsaDptr.Update(Dset,"dt_Account");
//dataGrid1.Update();
}

but still its not updating the table



0
Mohammed NasmanSoftware DeveloperCommented:
Do you have a primay key in dt_Account table?
if you don't, update will not work
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
arvshaAuthor Commented:
ya it hasa primary key but still its not working what should I do.

Its urgent please you techi people help me
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.