Dept in Checkbox
Gender in Radio Button
for that i want to write the code and save in the database.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Dec 5, 2012, 7:19 AM
Satyapriya NayakPosted Oct 25, 2012, 5:29 AM
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Radio_check
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
protected void Button1_Click(object sender, EventArgs e)
{
if (rb1.Checked == true )
{
SqlConnection con = new SqlConnection(strConnString);
com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "insert into login values(@Dept,@Gender)";
com.Parameters.Clear();
com.Parameters.AddWithValue("@Dept", chk1.Text);
com.Parameters.AddWithValue("@gender", rb1.Text);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
con.Close();
lblmsg.Text = "Data entered successfully!!!";
clear();
}
else
{
SqlConnection con = new SqlConnection(strConnString);
com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "insert into login values(@Dept,@Gender)";
com.Parameters.Clear();
com.Parameters.AddWithValue("@Dept", chk1.Text);
com.Parameters.AddWithValue("@gender", rb2.Text);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
con.Close();
lblmsg.Text = "Data entered successfully!!!";
clear();
}
}
void clear()
{
rb1.Checked = false;
rb2.Checked = false;
chk1.Checked = false;
}
}
}
Neha SharmaPosted Oct 25, 2012, 5:29 AM
Satyapriya NayakPosted Oct 25, 2012, 5:00 AM