Hi, i'm working on my first project on asp.net using c#.
I'm adding a couble of fields to database but i need the primary key of the master table to add it to sub table.
The database contains 2 tables :
Question Table :questionID(pri mary key and identity) , questionInText
Answer table : answerID , answer1,answer2 , questionID
code used to insert to db :
questionID is auto increment.
The question is : How i get questionID after adding to database without using sql statment ?
please help.
I'm adding a couble of fields to database but i need the primary key of the master table to add it to sub table.
The database contains 2 tables :
Question Table :questionID(pri mary key and identity) , questionInText
Answer table : answerID , answer1,answer2 , questionID
code used to insert to db :
Code:
string strInsert = "Insert INTO question(questionInText)Values(@questionInText)"; cmdInsert = new SqlCommand(strInsert , conn); cmdInsert .Parameters.AddWithValue("questionInText", txtQuestion.Text); cmdInsert.ExecuteNonQuery();
The question is : How i get questionID after adding to database without using sql statment ?
please help.
Comment