I'm having trouble to use compare the value off that table using OleDbDataReader, please help correct my code:
string connectionString = "(connect goes here)";
string sql = "SELECT isActived FROM List WHERE ID=@dotnet.itags.org.ID";
SqlConnection conn = new SqlConnection(connectionString);
SqlDataReader reader = null;
conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
cmd.Parameters.Add("@dotnet.itags.org.license", "(my id number goes here)");
reader = cmd.ExecuteReader();
(something wrong with this code:) bool temp = reader["isActived"];
(or this:) if (reader["isActived"] == true)
reader.Close();
conn.Close();
TIA
After a call to ExecuteRead, the reader is positioned before the first row. You must call reader.Read() to position the reader on a row before you attempt to access any data.
If you only get one value back, you may try this:
bool temp = cmd.ExecuteScalar();
thanks DMW, Jimmy, looks like ExecuteScalar would help me save a couple lines of code :)
0 comments:
Post a Comment