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.
SenthilkumarPosted Apr 7, 2012, 3:48 AM
Dorababu MekaPosted Apr 7, 2012, 2:39 AM
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();
Dorababu MekaPosted Apr 7, 2012, 2:36 AM
label.text=ds.tables[0].rows[0]["yourcol"].tostring();
Arvind YadavPosted Apr 7, 2012, 2:30 AM
Dorababu MekaPosted Apr 7, 2012, 2:06 AM
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