how to insert new row in datbase with dataset [Resolved]

Posted by Prabhakar under ASP.NET on 1/29/2011 | Points: 10 | Views : 9363 | Status : [Member] [MVP] | Replies : 5
hi evryone,

i am write this code it's working . data show in gridview but data not update in Sql dat base .. any suggestion

cmd = new SqlCommand("Select * from NewTryTable", localclass1.mycon);
adp = new SqlDataAdapter(cmd);
ds = new DataSet();
adp.Fill(ds);
DataRow nRow = ds.Tables[0].NewRow();
nRow["Name"] = "Prem";
nRow["Password"] = "Prabhu";
ds.Tables[0].Rows.Add(nRow);
ds.GetChanges();
gv.DataSource = ds.Tables[0];
gv.DataBind();

Best Regard's
Prabhakar



Responses

Posted by: Ddd on: 1/30/2011 [Member] Silver | Points: 50

Up
0
Down

Resolved
Hi Prbhakar,
please try this code:
cmd = new SqlCommand("Select * from NewTryTable", localclass1.mycon);
adp = new SqlDataAdapter(cmd);
ds = new DataSet();
adp.Fill(ds);
DataRow nRow = ds.Tables[0].NewRow();
nRow["Name"] = "Prem";
nRow["Password"] = "Prabhu";
ds.Tables[0].Rows.Add(nRow);
//add this line
SqlCommandBuilder cd=new SqlCommandBuilder(adp);

adp.Update(ds.Tables[0]);
gv.DataSource = ds.Tables[0];
gv.DataBind();


dinesh k.

Prabhakar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vforvijay on: 1/29/2011 [Member] Starter | Points: 25

Up
0
Down
hi.prabhakar
if you want edit the item in gridview make sure you add edititmetemplate field and command field in grid view in client side .....
and write the update query in row updating field....
http://vbdotnetaddict.blogspot.com

Prabhakar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/29/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down

Posted by: Sathya4260 on: 1/29/2011 [Member] Starter | Points: 25

Up
0
Down
hi prbhakar,

Can you post ur codes, so that we can find where you went wrong...

Just fetch the data's to Edit Template of grid view and then use the same steps to update the data's separetely,


Sathish Kumar S

Prabhakar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 1/31/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi dinesh ...


thanks for this code .. it's very use full for me ... and i am click also ur answer Mark as answer



Best Regard's
Prabhakar

Prabhakar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response