hi karthik,thank you for your reply,it's so helping me,and i have another problem.i.e,
i have one registration page, contain columns as UserID,FirstName,LastName,Address,ContactNo,DOB,Gender,EmailID.
when i entering all the data into textboxes,then clicki on submit button button it is going to next page,but the values are not storing into database,can you please check my code,and tell me where the mistake.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace newonlineexam
{
public partial class Register1 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("user id=sa;password=Ektha@2013;Data Source=EKTHA-3D34;Initial Catalog=OnlineExam");
Random rn = new Random();
// SqlCommand cmd = new SqlCommand();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Label17.Text = rn.Next(1000).ToString();
}
}
protected void Button1_Click1(object sender, EventArgs e)
{
con.Open();
//Session["User ID"] = TextBox4.Text;
SqlCommand cmd = new SqlCommand("insert into Registration(UserID,FirstName,LastName,Address,ContactNo,DOB,Gender,EmailID) values('" + Label17.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + RadioButtonList1.SelectedItem.Text + "','" + TextBox7.Text + "')", con);
cmd.ExecuteNonQuery();
//string s1 = "insert into Registration(UserID,FirstName,LastName,Address,ContactNo,DOB,Gender,EmailID) values('" + Label17 + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + RadioButtonList1.SelectedItem.Text + "','" + TextBox7.Text + "')";
//SqlCommand cmd = new SqlCommand(s1, con);
cmd.ExecuteNonQuery(); cmd.Connection = con;
cmd.CommandText = "select count(*) from Registration where FirstName='" + TextBox2.Text + "'";
int i = int.Parse(cmd.ExecuteScalar().ToString());
if (i == 0)
{
Session["id"] = Label17.Text;
Session["FirstName"] = TextBox2.Text;
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
RadioButtonList1.Items[0].Selected = false;
RadioButtonList1.Items[1].Selected = false;
Label17.Text = rn.Next(1000).ToString();
Response.Redirect("RegAck.aspx");
}
else
{
Label1.Text = "UserName already exists...";
}
con.Close();
}
protected void Button2_Click1(object sender, EventArgs e)
{
TextBox2.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
RadioButtonList1.Items[0].Selected = false;
RadioButtonList1.Items[1].Selected = false;
}
}
}
manimala
Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator