- Let table name is tblInfo and column name is colID and colName, where colID is auto generated (pk). you need to get current colID value after data insert.
- let write insert command INSERT INTO tblInfo(colName) VALUES('imran');
- Add this SELECT SCOPE_IDENTITY();
- so its looks like : INSERT INTO tblInfo(colName) VALUES('imran');
SELECT SCOPE_IDENTITY(); - then in C# :
object objRet=null;
string _SQL="INSERT INTO tblInfo(colName) VALUES('imran');
SELECT SCOPE_IDENTITY();";
_sqlCommand=new SqlCommand(_SQL,_sqlConnection);
objRet=_sqlCommand.ExecuteScalar()
;returnID=Convert.ToInt32(objRet.ToString());
Then you can get inserted ID value in returnID.
No comments:
Post a Comment