{System.Data.SqlClient.SqlErrorCollection}'=' 附近有语法错误。
txtConnectionString.Text = "Data Source=USER-20140828EH\\YANGLU;database=Bank;uid=sa;pwd=110478";
SqlConnection myConnection = new SqlConnection(txtConnectionString.Text);
SqlCommand myCommand = new SqlCommand("update" + txtFromBank.Text + "set balance=balance+@amount where account=@account", myConnection);
myCommand.Parameters.Add(new SqlParameter("@account", SqlDbType.VarChar, 50));
myCommand.Parameters["@account"].Value = txtFromAccount.Text;
myCommand.Parameters.Add(new SqlParameter("@amount", SqlDbType.Money, 8));
myCommand.Parameters["@amount"].Value = int.Parse(txtAmount.Text);
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
运行后会提示:
'=' 附近有语法错误。
为什么呢????
SqlConnection myConnection = new SqlConnection(txtConnectionString.Text);
SqlCommand myCommand = new SqlCommand("update" + txtFromBank.Text + "set balance=balance+@amount where account=@account", myConnection);
myCommand.Parameters.Add(new SqlParameter("@account", SqlDbType.VarChar, 50));
myCommand.Parameters["@account"].Value = txtFromAccount.Text;
myCommand.Parameters.Add(new SqlParameter("@amount", SqlDbType.Money, 8));
myCommand.Parameters["@amount"].Value = int.Parse(txtAmount.Text);
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
运行后会提示:
'=' 附近有语法错误。
为什么呢????
...全文
请发表友善的回复…
发表回复
KeepSayingNo 2014-09-18
- 打赏
- 举报
你用profier跟踪下看看执行的SQL是什么,在数据库里是否能执行
Tiger_Zhao 2014-09-18
- 打赏
- 举报
//表名两边缺少空格
"update " + txtFromBank.Text + " set balance=balance+@amount where account=@account"
zywandy 2014-09-18
- 打赏
- 举报
去查一下。应该是哪个文本框没有输入数据导致的错误
Lu_young 2014-09-18
- 打赏
- 举报
另外为什么用textbox中的输入的数据库链接地址无法打开数据库?
Lu_young 2014-09-18
- 打赏
- 举报
好了,,谢谢!!!
Tiger_Zhao 2014-09-18
- 打赏
- 举报
Data Source=USER-20140828EH\\YANGLU;database=Bank;uid=sa;pwd=110478
文本框内容又不是代码,转义符起什么作用?
文本框内容又不是代码,转义符起什么作用?
Lu_young 2014-09-18
- 打赏
- 举报
文本框里,都有数据,txtConnectionString.Text中就是数据库的连接地址
Data Source=USER-20140828EH\\YANGLU;database=Bank;uid=sa;pwd=110478
Tiger_Zhao 2014-09-18
- 打赏
- 举报
ConnectionString 写错了啊!
Lu_young 2014-09-18
- 打赏
- 举报
感谢3楼解答。。。但是为什么用textbox中的输入的数据库链接地址,,打开数据库时,会出现{"实例失败。"}???
SqlConnection myConnection = new SqlConnection(txtConnectionString.Text);
SqlCommand myCommand = new SqlCommand("update " + txtFromBank.Text + " set balance=balance+@amount where account=@account", myConnection);
myCommand.Parameters.Add(new SqlParameter("@account", SqlDbType.VarChar, 50));
myCommand.Parameters["@account"].Value = txtFromAccount.Text;
myCommand.Parameters.Add(new SqlParameter("@amount", SqlDbType.Money, 8));
myCommand.Parameters["@amount"].Value = int.Parse(txtAmount.Text);
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();