string getTitle = this.TextBox1.Text;
string getAuthor = this.TextBox2.Text;
string sql = "insert into 表(title,author) values ('" + getTitle + "','" + getAuthor + "'); select @@identity AS RID";
string getAuthor = this.TextBox2.Text;
string sql = "insert into 表(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 +"','新部门测试')";
string connStr = System.Configuration.ConfigurationManager.AppSettings["fff"].ToString();
SqlConnection myconn = new SqlConnection(connStr);
SqlCommand mycomm = new SqlCommand(sql,myconn);
myconn.Open();
SqlTransaction myTrans = myconn.BeginTransaction();
mycomm.Transaction = myTrans;
try
{
mycomm.ExecuteNonQuery();
myTrans.Commit();
}
catch
{
myTrans.Rollback();
}
finally
{
myconn.Close();
}
string connStr = System.Configuration.ConfigurationManager.AppSettings["fff"].ToString();
SqlConnection myconn = new SqlConnection(connStr);
SqlCommand mycomm = new SqlCommand(sql,myconn);
myconn.Open();
SqlTransaction myTrans = myconn.BeginTransaction();
mycomm.Transaction = myTrans;
try
{
mycomm.ExecuteNonQuery();
myTrans.Commit();
}
catch
{
myTrans.Rollback();
}
finally
{
myconn.Close();
}