sql 语句在MSSMS 执行返回受影响的行数为2, new SqlCommand().ExecuteNonQuery() 执行返回 0 5
贴出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
我实在找不到问题所在了,多谢赐教!
就剩下这么点分了,希望高手本着解决问题,助人为乐的心态帮个忙。 展开
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
我实在找不到问题所在了,多谢赐教!
就剩下这么点分了,希望高手本着解决问题,助人为乐的心态帮个忙。 展开
2个回答
展开全部
你的事物还要Commit()
追问
插入不成功不需要Commit()吧,我的问题是为什么会插入不成功,而在MSSMS中执行 sql 是可以插入成功的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询