Joegi
Joegi

Reputation: 27

C# Visual Studio No value given for one or more required parameters

if (kmatch == 1)
{
    con.Open();

    int a;
    a = Convert.ToInt16(txtBalance.Text);
    a = int.Parse(txtBalance.Text);

    OleDbCommand com = new OleDbCommand();
    com.Connection = con;
    String query = "update PlayerAccount set Balance='" + a + "'where Player_User=" + txtUser.Text + "";
    com.CommandText = query;
    com.ExecuteNonQuery();
    MessageBox.Show("PointCard Credited to your Account");
    con.Close();
}

At first I thought that it needed to be converted to int. but now I am out of ideas.

Database Table:PlayerAccount

'Balance' is an int

Just started learning this. any help would be appreciated.

Upvotes: 2

Views: 184

Answers (2)

Saragis
Saragis

Reputation: 1792

"'where Player_User="

Should be

" 'where Player_User="

You are missing a space and appending too much together. But as Alex K. said you should convert this to a parametrized query.

Upvotes: 0

Michael
Michael

Reputation: 1596

You should change String query = "update PlayerAccount set Balance='" + a + "'where Player_User=" + txtUser.Text + ""; to String query = "update PlayerAccount set Balance= " + a + " where Player_User='" + txtUser.Text + "'";.

You need to include single quotes around text values in SQL and you don't need to include them around numeric values (though you can if you wish).

However, it looks like you are opening yourself up to SQL injection attacks.

Look into using parameterized commands instead of dynamically writing SQL.

Documentation for SQL Parameters here.

Upvotes: 2

Related Questions