Reputation: 1
Im not sure how this is not working, but its not putting the quiz grade in the student table, can anyone help? here is my code.
private void button9_Click(object sender, EventArgs e)
{
int x = 0;
if (textBox20.Text == "yours" || textBox20.Text == "Yours" || textBox20.Text == "YOURS")
{
x++;
}
if (textBox21.Text == "mine" || textBox21.Text == "Mine" || textBox21.Text == "MINE")
{
x++;
}
if (textBox22.Text == "his" || textBox22.Text == "His" || textBox22.Text == "HIS")
{
x++;
}
if (textBox23.Text == "yours" || textBox23.Text == "Yours" || textBox23.Text == "YOURS")
{
x++;
}
SqlConnection con = new SqlConnection(connStr);
str = "UPDATE Student SET (Q1 ='" + x + "') WHERE (Username = '" + this.textBox3.Text + "' , Password = '" + this.textBox4.Text + "')";
try
{
this.studentTableAdapter5.Update(this.cAIDataSet5.Student);
MessageBox.Show("Your Score is: " + x);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
I'm not sure where I went wrong, it doesn't show any errors at all.
Upvotes: 0
Views: 112
Reputation: 10538
You don't execute your sql query anywhere.
You will need to do something along these lines:
using(var con = new SqlConnection(connStr))
{
var command = new SqlCommand(str, connStr);
command.ExecuteNonQuery(command);
}
As commentors have mentioned your approach is vulnerable to Sql injection. While the context of your question makes this somewhat irrelevant it is good to be aware of it. You can read about sql injection here.
Upvotes: 1