Sir,
i am generating value in sql using identity. this value i want to display in my application in Text box or label. how to display this value in TextBox or Label.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Hemant KumarRank #1,202 · 1.5K reputationPosted Apr 2, 2012, 4:13 AM EDT
// Use @@IDENTITY to work out the primary key of // the new row and display it command.CommandText = "SELECT @@IDENTITY"; id = Convert.ToInt32(command.ExecuteScalar());Gohil JayendrasinhRank #490 · 5K reputationPosted Apr 2, 2012, 4:24 AM EDT
using LINQ
MyBDDDataContext db = new MyBDDDataContext();
record newRecord = new record();
newRecord.record_title = newRecordBDD.Title;
newRecord.record_text = newRecordBDD.Text;
newRecord.record_date = DateTime.Now;
db.records.InsertOnSubmit(newRecord);
try
{
db.SubmitChanges();
int id = newRecord.ID; // you can access your newRecord to get the ID
}
catch (Exception)
{
throw;
}
If it's helpful to you then please check as Accepted Answers
SenthilkumarRank #387 · 6.5K reputationPosted Apr 2, 2012, 6:24 AM EDT