This is my code:
OleDbCommand Cmd = new OleDbCommand();
Cmd.Connection = MyConn;
Cmd.CommandText = "SELECT * FROM catalogue WHERE id = '" + questionid + "'";
OleDbDataReader read = Cmd.ExecuteReader();
int id = 0;
while (read.Read())
{
id = Convert.ToInt32(read["id"]);
}
Here's the error it gives me:
Line 27: Cmd.CommandText = "SELECT * FROM catalogue WHERE id = '" + questionid + "'";
Line 28:
Line 29: OleDbDataReader read = Cmd.ExecuteReader(); // The error is here
Line 30:
Line 31: int id = 0;
I know there is also another question about the same issue on Stack Overflow, but it doesn't seem to solve my problem (it may solve yours, so I put a link).
questionid
andid
incatalogue
are of same/equivalent datatype. If so make sure questionid is not null. Nice point by @nvoigt, you should use parameters - Pranav Singh