sql 语句在MSSMS 执行是没有问题的, new SqlCommand().ExecuteNonQuery() 执行会返回0
贴出C#代码SqlConnectionconn=Base.GetSqlConnect(Base.sqlConnString());SqlTransactiontran=c...
贴出C# 代码
SqlConnection conn = Base.GetSqlConnect(Base.sqlConnString());
SqlTransaction tran = conn.BeginTransaction();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.Transaction = tran;
string sql = string.Format(@"INSERT INTO dbo.B_User_Account_Info(UserCode,UseType,Charge_Type, Charge,
Charge_Note, Charge_Date, Charger, InterSeq, PipeSetID)
Select UserCode, UseType, Charge_Type, ABS(Charge) as Charge,
Replace(Charge_Note, '扣款', '返款') as Charge_Note ,GetDate() as Charge_Date, Charger, InterSeq, PipeSetID
From B_User_Account_Info Where InterSeq In(Select InterSeq From B_Sms_FileDeal_Info
Where SendUser = '{0}' and isDone = -2)", "test");
//执行sql
comm.CommandText = sql;
bool bl = comm.ExecuteNonQuery() > 0;
bl 始终为false,
换成 comm.ExcuteScalar() 始终为 null
我实在找不到问题所在了,多谢赐教!
在 MSSMS 执行返回 受影响的行数为2 展开
SqlConnection conn = Base.GetSqlConnect(Base.sqlConnString());
SqlTransaction tran = conn.BeginTransaction();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.Transaction = tran;
string sql = string.Format(@"INSERT INTO dbo.B_User_Account_Info(UserCode,UseType,Charge_Type, Charge,
Charge_Note, Charge_Date, Charger, InterSeq, PipeSetID)
Select UserCode, UseType, Charge_Type, ABS(Charge) as Charge,
Replace(Charge_Note, '扣款', '返款') as Charge_Note ,GetDate() as Charge_Date, Charger, InterSeq, PipeSetID
From B_User_Account_Info Where InterSeq In(Select InterSeq From B_Sms_FileDeal_Info
Where SendUser = '{0}' and isDone = -2)", "test");
//执行sql
comm.CommandText = sql;
bool bl = comm.ExecuteNonQuery() > 0;
bl 始终为false,
换成 comm.ExcuteScalar() 始终为 null
我实在找不到问题所在了,多谢赐教!
在 MSSMS 执行返回 受影响的行数为2 展开
1个回答
展开全部
SqlConnection conn = Base.GetSqlConnect(Base.sqlConnString());
SqlTransaction tran = conn.BeginTransaction();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.Transaction = tran;
string sql = string.Format(@"INSERT INTO dbo.B_User_Account_Info(UserCode,UseType,Charge_Type, Charge,
Charge_Note, Charge_Date, Charger, InterSeq, PipeSetID)
Select UserCode, UseType, Charge_Type, ABS(Charge) as Charge,
Replace(Charge_Note, '扣款', '返款') as Charge_Note ,GetDate() as Charge_Date, Charger, InterSeq, PipeSetID
From B_User_Account_Info Where InterSeq In(Select InterSeq From B_Sms_FileDeal_Info
Where SendUser = '{0}' and isDone = -2)", "test");
//执行sql
comm.CommandText = sql+“ select @@ROWCOUNT”;
bool bl = Convert.ToInt32(comm.ExecuteScalar()) > 0;
你的返回值 是一个object,需要转换的。
追问
select @@ROWCOUNT 返回居然还是0啊;
我跟踪进去发现comm.ExecuteNonQuery() =0。 在数据库执行sql 语句 是有 受影响的行数的返回的。
追答
你是不是对数据库设置过啊
开始加上 set nocount off
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询