Click here to Skip to main content
16,014,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two RadioButtons(MaleRB and FmaleRB) And in my data base I have two column Male and female, If I select MaleRB, It should get updated as 1 in my database ie, in Male column and 0 in Female column And Viceversa.

Can any one help me out please.
Posted
Updated 26-Jun-18 6:16am
v2
Comments
RaisKazi 13-Dec-11 1:39am    
I would suggest to have only one Column "Gender" in Database Table, and then you may insert values "M"/"F" based on user selection.
Code 89 13-Dec-11 2:10am    
you just insert it by writing an insert querry,you need to write this in your value,'"+RadioButton.SelectedValue+"'..

C#
string rbValue;

if (MaleRb.Checked == true)
{
                rbValue = "1";
                mycommand.Parameters.AddWithValue("@Gender", rbValue);
            }
            if (FmaleRb.Checked == true)
            {
                rbValue = "0";
                mycommand.Parameters.AddWithValue("@Gender", rbValue);
            }



Can solve your problem using this
 
Share this answer
 
Comments
Abhinav S 13-Dec-11 2:56am    
Close to my answer. 5 though.
You know, the best solution for this is to have a single gender flag into your table. Normalization of fields should be a practice to everyone. 0 for male and 1 for female or viceversa. With that, you would have lesser logic in updating gender status.

Cheers!
Eduard
 
Share this answer
 
Comments
Abhinav S 13-Dec-11 2:56am    
Yes point- there is no need to have two columns. 5.
[no name] 13-Dec-11 3:37am    
thanks!
raj ch 13-Dec-11 3:53am    
formalization is the best technique to be remembered while coding. my vote of 5
[no name] 13-Dec-11 4:00am    
thanks!
Use if Else Condition to set 0 and 1
Now if rb = 1 then male and rb=0 then female .

in coding 

int x ;
if ( RadioButton1.Checked == true)
{
        x = 1;
}
else if(RadioButton2.Checked == true)
{
      x=0;
} 
 
Share this answer
 
v4
Comments
manjunath NIE 13-Dec-11 1:41am    
What to write in Code
Member 13847218 26-Jun-18 12:46pm    
private void button4_Click(object sender, EventArgs e)
{
string source = ("Data Source=DESKTOP-8BEJFRN\\SQLEXPRESS;Initial Catalog=mywork;Integrated Security=True");
SqlConnection con = new SqlConnection(source);
con.Open();
MessageBox.Show("Your Search");

string sqlselectquery = "SELECT * from cust WHERE [Nic No]= '" + txtnicn.Text + "'";
SqlCommand cmd = new SqlCommand(sqlselectquery, con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
txtcuid.Text = (dr["Custermer Id"].ToString());
txtnam.Text = (dr["name"].ToString());
txtad.Text=(dr["Address"].ToString());
txtcontn.Text = (dr["Mobile no"].ToString());




con.Close();
}





{



}

}
how do old rady sql save search button textbox value nic no enter all value display... importance - radiobutton(gender)
Have a parameter for the two columns in the C# code.
Based on value chosen in the form, you can use the checked property to figure out what needs to be inserted in the database.

Example
C#
if(MaleRB .Checked== "1")
    SqlDataSource1.UpdateParameters[0].DefaultValue = "True";

else
    SqlDataSource1.UpdateParameters[0].DefaultValue = "False";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900