ExecuteNonQuery 对于 UPDATE、INSERT 和 DELETE 语句,返回值为该命令所影响的行数。对于所有其他类型的语句,返回值为 -1。如果发生回滚,返回值也为 -1
示例:
SqlConnection conn = new SqlConnection(connstr);//connstr 数据库连接字符信息
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "Update Training set Hours = 600 where Trainingcode = @Trainingcode";
SqlParameter para = comm.Parameters.Add("@Trainingcode", SqlDbType.Char, 10);
para.Value = txtTrainCode.Text;
conn.Open();
int numUpdated = comm.ExecuteNonQuery();//numUpdated 获取UPdate后影响的行数
conn.Close();
ExecuteNonQuery
最新推荐文章于 2021-01-26 18:19:18 发布