What you're trying to do is to get a result from the SQL server, and cast it as a boolean.
What you're actually doing is trying to convert your SQL command into a boolean.
What you need to do is actually open the connection to the SQL server and execute your query. But it's a bit more complex than that...
if (con.State != ConnectionState.Open)
con.Open();
Boolean genderval = false;
SqlCeCommand gendercmnd = new SqlCeCommand(@"SELECT Gender FROM Std_info WHERE Std_id='" + TextBox1.Text + "'", con);
gendercmnd.Connection.Open(); // Open the connection using the gendercmd string.
sqlReader = gendercmnd.ExecuteReader(); // Execute the read, which returns an SqlCEDataReader object that we can use to access the data.
genderval = Convert.ToBoolean(gendercmndResult);
if (genderval == true)
Convert.ToBoolean(radioButton1.Checked);
else
Convert.ToBoolean(radioButton2.Checked);
con.Close();
Now we need to take the value from the reader, and cast that as a boolean.
if (con.State != ConnectionState.Open)
con.Open();
Boolean genderval = false;
String gendercmndResult = null;
SqlCeCommand gendercmnd = new SqlCeCommand(@"SELECT Gender FROM Std_info WHERE Std_id='" + TextBox1.Text + "'", con);
gendercmnd.Connection.Open(); // Open the connection using the gendercmd string.
sqlReader = gendercmnd.ExecuteReader(); returns an SqlCEDataReader object that we can use to access the data.
while (sqlReader.Read(){ //While the reader is reading...
gendercmndResult = (sqlReader.GetString(0)); //Assign the returned value from the SQL server to a string called gendercmndResult
}
genderval = Convert.ToBoolean(gendercmndResult); //Now we can cast the string as a bool
if (genderval == true)
Convert.ToBoolean(radioButton1.Checked);
else
Convert.ToBoolean(radioButton2.Checked);
con.Close();