hi ,please tell me,where is the mistake,the values are not storing into database,please help me
my source code is...........
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 == 1)
{
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;
}
}
}
my c# code is....
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 Home : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("user id=sa;password=Ektha@2013;Data Source=EKTHA-3D34;Initial Catalog=OES");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
String s1 = "Select * from Registration where UserType='" + DropDownList1.SelectedItem.Text + "' and UserID'" + TextBox1.Text + "' and Password='" + TextBox2 + "'";
SqlCommand cmd= new SqlCommand(s1,con);
cmd.ExecuteScalar();
if(DropDownList1.SelectedItem.Text =="Student")
{
Response.Redirect("Student.aspx");
}
else if(DropDownList1.SelectedItem.Text=="Admin")
{
Response.Redirect("Admin.aspx");
}
else
{
Response.Redirect("InstructorHome.aspx");
}
}
// if (DropDownList1.SelectedItem.Text == "Student")
//{
// Session["uid"] = TextBox1.Text;
// }
//SqlDataReader da;
// da = cmd.ExecuteReader();
//if (da.Read())
//Response.Redirect("Toproceed.aspx");
// //else
// //Response.Write("not authenticated");
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Register1.aspx");
}
}
}
manimala
Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator