Display SQL information on C# RadioButtons

600 Views Asked by At

My C# program is connected to my SQL CE Database. I use a SQLCEDATAREADER to fill some of the textboxes in my program. I have a "Gender" column in my database and a radiobutton with Male and Female. If a certain entry in my database has "M" in the gender column, how can I make the Male radio button appear pressed?

I tried

if(dr["Gender"].ToString = "M")
{
    rbMale = true
}

That obviously didnt work.

3

There are 3 best solutions below

3
Vynhoû Tawa On BEST ANSWER
if(dr["Gender"].ToString() = "M")
    rbMale.Checked = true
else
    rbFemale.Checked = true
0
bittusarkar On

If rbMale is the name of your radio button control, you can mark it checked by setting its Checked property to true.

rbMale.Checked = true;

1
jammy On

Perhaps collapse to one line -

rbMale.Checked = (Convert.ToString(dr["Gender"])=="M");