C# SQL Exception Error
-
Hi Im having a problem with SQL and C#. Here is a copy of my code where the problem is occurring.
private void button1_Click(object sender, EventArgs e) { oleDbConnection1.Open(); oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM NASDATA where account = 'test'"; oleDbDataAdapter1.UpdateCommand.ExecuteNonQuery(); oleDbConnection1.Close(); }
I get an exception error on the ExecuteNonQuery line. NullReferenceException was unhandled. Object refernece not set to an instance of an object. On the design page i have the Oledb connector and dataadapter setup, and the test connection succeeds. Note: I had this same problem using an Access database to. I really hope somebody can help. Many thanks! -
Hi Im having a problem with SQL and C#. Here is a copy of my code where the problem is occurring.
private void button1_Click(object sender, EventArgs e) { oleDbConnection1.Open(); oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM NASDATA where account = 'test'"; oleDbDataAdapter1.UpdateCommand.ExecuteNonQuery(); oleDbConnection1.Close(); }
I get an exception error on the ExecuteNonQuery line. NullReferenceException was unhandled. Object refernece not set to an instance of an object. On the design page i have the Oledb connector and dataadapter setup, and the test connection succeeds. Note: I had this same problem using an Access database to. I really hope somebody can help. Many thanks! -
Hi Im having a problem with SQL and C#. Here is a copy of my code where the problem is occurring.
private void button1_Click(object sender, EventArgs e) { oleDbConnection1.Open(); oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM NASDATA where account = 'test'"; oleDbDataAdapter1.UpdateCommand.ExecuteNonQuery(); oleDbConnection1.Close(); }
I get an exception error on the ExecuteNonQuery line. NullReferenceException was unhandled. Object refernece not set to an instance of an object. On the design page i have the Oledb connector and dataadapter setup, and the test connection succeeds. Note: I had this same problem using an Access database to. I really hope somebody can help. Many thanks!I apologise, i realise i put the update command instead of select. However, i get the same problem (nullreferenceexception) if i change the code to the following:
oleDbConnection1.Open(); oleDbDataAdapter1.UpdateCommand.CommandText = "UPDATE NASDATA SET EMAIL = 'TESTEMAIL' WHERE ACCOUNT = 'TEST'"; oleDbDataAdapter1.UpdateCommand.ExecuteNonQuery(); oleDbConnection1.Close();
It breaks on the UpdateCommand.CommandText line, saying NullReferenceException was unhandled. Object refernece not set to an instance of an object. -
I apologise, i realise i put the update command instead of select. However, i get the same problem (nullreferenceexception) if i change the code to the following:
oleDbConnection1.Open(); oleDbDataAdapter1.UpdateCommand.CommandText = "UPDATE NASDATA SET EMAIL = 'TESTEMAIL' WHERE ACCOUNT = 'TEST'"; oleDbDataAdapter1.UpdateCommand.ExecuteNonQuery(); oleDbConnection1.Close();
It breaks on the UpdateCommand.CommandText line, saying NullReferenceException was unhandled. Object refernece not set to an instance of an object.