String Gettitle = This . Textbox1.text;
String Getauthor = This . Textbox2.text;
String SQL = " Insert into table (title, author) values (' " + Gettitle + " ',' " + Getauthor + " '); Select @ identity as RID " ; // String SQL = "insert into Department (departmentname, departmentcode) values ('" + getname + "', '" + getcode + "'); insert into Department (ID, departmentname) values ('"+ @ identity +"', 'new Department test ')";
String Connstr = system. configuration. configurationmanager. appsettings [ " Fff " ]. Tostring ();
Sqlconnection myconn =NewSqlconnection (connstr );
Sqlcommand mycomm =NewSqlcommand (SQL, myconn );
Myconn. open ();
Sqltransaction mytrans = myconn. begintransaction ();
Mycomm. Transaction = mytrans;
try
{< br> mycomm. executenonquery ();
mytrans. commit ();
}< br> catch
{< br> mytrans. rollback ();
}< br> finally
{< br> myconn. close ();
}