ExecuteNonQuery()方法

ExecuteNonQuery()方法对Update,Insert,Delete语句有效,对select无效

using (var conn = new SqlConnection(connectionString))
using (var cmd = new SqlCommand())
{
cmd.Connection = conn;

// SQL参数生成
string DataRepeatChecksql = "SELECT * FROM dbo.Used Where OtherID = @OtherID";
SqlParameter[] ps = {
new SqlParameter("@OtherID","dwada"), //usedInfodataOtherID
};
// 查询结果大于等于1
int issss= SqlHelper.ExecuteNonQuery(DataRepeatChecksql, ps);
System.Diagnostics.Debug.WriteLine("wwwww: "+usedInfodataOtherID);
System.Diagnostics.Debug.WriteLine(issss);
if (issss >= 1)
{
// 登录过时,判断结果=1
DataRepeatCheckResult = 1;
}
}

ExecuteNonQuery()方法主要用于用户更新数据,通常它使用Update,Insert,Delete语句来操作数据库,其方法返回值意义:对于 Update,Insert,Delete语句执行成功是返回值为该命令所影响的行数,如果影响的行数为0时返回的值为0,如果数据操作回滚得话返回值为-1。

详见SqlHelper

365个夜晚,我希望做到两天更一篇博客。加油,小白!
原文地址:https://www.cnblogs.com/qq2806933146xiaobai/p/13045267.html