How to retrive identity value of sql in textbox of C# application
i am genrating identity value in sql . this value i want to show in my textbox or label of the application of C#. how to retrive identity value into textbox to label of the the application. and what is the code of retriving identity value into textbox or label.

SenthilkumarRank #387 · 6.5K reputationPosted Apr 6, 2012, 11:48 PM EDT
Dorababu MekaRank #457 · 5.5K reputationPosted Apr 6, 2012, 10:06 PM EDT
open the connection
write your query in command object as follows
Select Identitycolumn from yourtable
fill to dataset using dataadapter
da.fill(ds);
But if you have multiple ID's it is hard to show the required. So post what you are exactly doing
Arvind Yadav45 reputationPosted Apr 6, 2012, 10:30 PM EDT
Dorababu MekaRank #457 · 5.5K reputationPosted Apr 6, 2012, 10:36 PM EDT
label.text=ds.tables[0].rows[0]["yourcol"].tostring();
Dorababu MekaRank #457 · 5.5K reputationPosted Apr 6, 2012, 10:39 PM EDT
sqlconnection con=new sqlconnection("your connection string");
sqlcommand cmd=new sqlcommand("select id from tblname",con);
con.open();
dataset ds=new dataset();
dataadapter da =new dataadapter();
da.selectcommand=cmd;
da.fill(ds):
con.close();
label1.text= ds.tables[0].rows[0]["id"].tostring();