SQL语法中有什么错误吗?
Sql语法:
UPDATE Table1 SET
Username='Diana' ,
Email='Diana@gmail.com' ,
FirstName='' ,
LastName='' ,
CrediCardNum=''
Where Username='Diana'
它一直给我错误:
没有给出一个或多个必需参数的值。
我尝试重新启动visual studio但不断给出相同的错误
c#code
f1.Connection1.Open();
OleDbCommand Command = new OleDbCommand();
Command.Connection = f1.Connection1;
if(m[6].Contains("Red"))
Command.CommandText = "UPDATE userdlt SET Username='"+textBox10.Text+"' , Email='"+textBox9.Text+"' , FirstName='"+textBox8.Text+ "',LastName='"+textBox7.Text+"',CrediCardNum='"+textBox6.Text+"' Where Username='"+m[0]+"'" ;
else
Command.CommandText = "UPDATE Table1 SET Username='"+textBox10.Text+"' , Email='"+textBox9.Text+"' , FirstName='"+textBox8.Text+ "' , LastName='"+textBox7.Text+"' , CrediCardNum='"+textBox6.Text+"' Where Username='"+m[0]+"'" ;
Clipboard.SetText(Command.CommandText);
Command.ExecuteNonQuery();
f1.Connection1.Close();
MessageBox.Show("Member UPDATED Succefully");
m数组是字符串数组
答案 0 :(得分:1)
您的专栏名称creditcardNum
缺少t
Command.CommandText = "UPDATE Table1 SET Username='"+textBox10.Text+"' ,
Email='"+textBox9.Text+"' , FirstName='"+textBox8.Text+ "' ,
LastName='"+textBox7.Text+"' , CrediCardNum='"+textBox6.Text+"' Where
Username='"+m[0]+"'" ;
应该是
Command.CommandText = "UPDATE Table1 SET Username='"+textBox10.Text+"' ,
Email='"+textBox9.Text+"' , FirstName='"+textBox8.Text+ "' ,
LastName='"+textBox7.Text+"' , CreditCardNum='"+textBox6.Text+"' Where
Username='"+m[0]+"'" ;
您的表格定义图片CreditCardNum
答案 1 :(得分:0)
我怀疑' @'在电子邮件地址中使SqlCommand认为您正在传递参数。避免这种情况的方法如下:
string sql =" UPDATE myTable SET col1 = @ val1,col2 = @ val2 WHERE col3 = @ val3&#34 ;;
然后,一旦用这个SQL创建了命令对象:
myCommand.Parameters.AddWithValue(" val1"," anEmail@address.com");
等等。