C# No value given for one or more required parameters

90 views Asked by At

Is there anything Wrong in SQL Syntax ?

Sql syntax :

UPDATE Table1 SET 
       Username='Diana' , 
       Email='[email protected]' , 
       FirstName='' , 
        LastName='' , 
       CrediCardNum='' 
Where Username='Diana'

it Keeps Giving me the Error:

No value given for one or more required parameters.

I tried restarting visual studio but keeps giving the same error

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");

The m array is Array of Strings

2

There are 2 answers

3
Sachu On BEST ANSWER

Your column name creditcardNum missing 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]+"'" ;

it should be

 Command.CommandText = "UPDATE Table1 SET Username='"+textBox10.Text+"' ,
     Email='"+textBox9.Text+"' , FirstName='"+textBox8.Text+ "' ,
    LastName='"+textBox7.Text+"' , CreditCardNum='"+textBox6.Text+"' Where 
    Username='"+m[0]+"'" ;

Your table definition picture saying CreditCardNum

2
GinjaNinja On

I suspect that the '@' in the email address is making the SqlCommand think you are passing a parameter. Way to avoid this is as follows:

string sql = "UPDATE myTable SET col1 = @val1, col2=@val2 WHERE col3 = @val3";

then, once you have created the command object with this SQL:

myCommand.Parameters.AddWithValue("val1", "[email protected]");

and so on.