Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my form, for gender, I have used radio button list for male & female
Can someone pleasee tell me how am I suppose to fetch d selected value n store it in my table
Posted

1 solution

Hi,

Try this logic


string gender = string.Empty;
if (rbMale.Checked)
{
gender = "M";
}
else if (rbFemale.Checked)
{
gender = "F";
}
string connectionstr= ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO tablename(Gender) VALUES(@Gender)"))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("@Gender", gender);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
 
Share this answer
 
Comments
Member 11694853 20-May-15 1:27am    
Thanx shivram_i for d answer.
It really helped :)
Shivaram_i 20-May-15 1:28am    
Welcome... :)

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