C#Update的时候ExecuteNonQuery 出现语法错误
privatevoidbtnUpdate_Click(objectsender,EventArgse){try{stringupdata=string.Format("U...
private void btnUpdate_Click(object sender, EventArgs e)
{
try
{
string updata = string.Format("UPDATE Student SET LoginId = '{0}' LoginPwd = '{1}' studentName = '{2}', sex = '{3}', major = '{4}' Phone = '{5}' WHERE studentId = {6}",
txbLoginId.Text, txbPwd.Text, txbName.Text, txbSex.Text, txbMajor.Text, txbPhone.Text, txbId.Text);
SqlCommand command = new SqlCommand(updata,DBHelper.conn);
DBHelper.conn.Open();
int result = command.ExecuteNonQuery();
if (result > 0)
MessageBox.Show("{0} row has been updatad!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("User info is not updated!", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
DBHelper.conn.Close();
}
}
int result = command.ExecuteNonQuery();就是这句报错说LoginPwd附近出现语法错误 展开
{
try
{
string updata = string.Format("UPDATE Student SET LoginId = '{0}' LoginPwd = '{1}' studentName = '{2}', sex = '{3}', major = '{4}' Phone = '{5}' WHERE studentId = {6}",
txbLoginId.Text, txbPwd.Text, txbName.Text, txbSex.Text, txbMajor.Text, txbPhone.Text, txbId.Text);
SqlCommand command = new SqlCommand(updata,DBHelper.conn);
DBHelper.conn.Open();
int result = command.ExecuteNonQuery();
if (result > 0)
MessageBox.Show("{0} row has been updatad!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("User info is not updated!", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
DBHelper.conn.Close();
}
}
int result = command.ExecuteNonQuery();就是这句报错说LoginPwd附近出现语法错误 展开
2个回答
展开全部
你的LoginId = '{0}' LoginPwd = '{1}' studentName = '{2}', sex = '{3}', major = '{4}' Phone = '{5}'中间为什么有些加了逗号有些没有?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
UPDATE Student SET LoginId = '{0}' ,LoginPwd = '{1}', studentName = '{2}', sex = '{3}', major = '{4}' ,Phone = '{5}' WHERE studentId = {6}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询