-1
I have the following code at the event Validated textbox:
NpgsqlConnection conn = new NpgsqlConnection(
"Server=127.0.0.1; port=5432;User; Id=postgres; Password=572600;Database=Sistema");
conn.Open();
NpgsqlCommand cmd = new NpgsqlCommand(@"
SELECT * FROM usuario
WHERE codigo_usuario=" + textBox1.Text, conn);
NpgsqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
textBox2.Text = dr["nome"].ToString();
// checkBox1.Checked = dr["inativo"];
textBox3.Text = dr["senha"].ToString();
radioButton1.Text = dr["nivel"].ToString();
conn.Close();
}
The "inactive" field in the database is Boolean and I would like you to return the Checkbox according to true or false that is in the database record.
What probably happens is that the value of dr["inactive"] is not a boolean variable, although this field in the database is. Try the following: see, by debugging, the value of dr["inactive"]. If the value is, for example, "True", do: checkBox1.Checked = String.Equals(dr["inactive"]. Tostring(), "True");
– João Victor Sierra
João Victor Sierra that’s what I really needed thanks for the help I’m beginner in C# In case I need to convert a String field from the database, if true the radiobutton1 is checked, if it is falseu radiobutton2 is checked , how do ? radioButton1.Text = dr["nivel"]. Tostring(); that would be it ?
– Mateus Sabino
The answer solved your problem?
– Jéf Bueno