ASP.NET Registration Form

 ASP.NET Registration Form 

V.Tharmatha
College of Technology Jaffna NVQ Level 05 ICT

        protected void Button1_Click(object sender, EventArgs e)

        {

            Session["test"] = TextBox1.Text;

            Session["n"] = TextBox2.Text;

            Session["a"] = TextBox3.Text;

            if (RadioButton1.Checked == true)

            {

                Session["g"] = RadioButton1.Text;

            }

            else

            {

                Session["g"] = RadioButton2.Text;

            }

            Session["c"] = DropDownList1.Text;

            Session["p"] = TextBox4.Text;

           

            Response.Redirect("WebForm2.aspx");

       }

 

protected void Button2_Click(object sender, EventArgs e)

        {

            SqlConnection con = new SqlConnection(@"Data Source=(localdb)\sql1234;Initial Catalog=student;Integrated Security=True");

            con.Open();

            SqlCommand cmd = new SqlCommand("select * from stu where id='" + TextBox1.Text + "'", con);

            if (con.State != System.Data.ConnectionState.Open)

                con.Open();

            SqlDataReader reade = cmd.ExecuteReader();

            reade.Read();

            if (reade.HasRows)

            {

                TextBox1.Text = reade[0].ToString();

                TextBox2.Text = reade[1].ToString();

                TextBox3.Text = reade[2].ToString();

                if ((string)reade[3] == "male")

                {

                    RadioButton1.Checked = true;

                }

                else

                {

                    RadioButton2.Checked = true;

                }

                DropDownList1.Text = reade[4].ToString();

                TextBox4.Text = reade[5].ToString();

            }

 

 

using System.Data.SqlClient;

 namespace insert

{

    public partial class WebForm2 : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            string id = Convert.ToString(Session["test"]);

            Label1.Text = id;

            string name = Convert.ToString(Session["n"]);

            Label2.Text = name;

            string address = Convert.ToString(Session["a"]);

            Label3.Text = address;

            string gender = Convert.ToString(Session["g"]);

            Label4.Text = gender;

            string corse = Convert.ToString(Session["c"]);

            Label5.Text = corse;

            string phone = Convert.ToString(Session["p"]);

            Label6.Text = phone;

        }

         protected void Button1_Click(object sender, EventArgs e)

        {

            SqlConnection con = new SqlConnection(@"Data Source=(localdb)\sql1234;Initial Catalog=student;Integrated Security=True");

            con.Open();

            SqlCommand cmd = new SqlCommand("insert into stu values(@id,@name,@addres,@course,@gender,@phone)", con);

            cmd.Parameters.AddWithValue("@id", Label1.Text).ToString();

            cmd.Parameters.AddWithValue("@name", Label2.Text).ToString();

            cmd.Parameters.AddWithValue("@addres", Label3.Text).ToString();

            cmd.Parameters.AddWithValue("@gender", Label4.Text).ToString();

            cmd.Parameters.AddWithValue("@course", Label5.Text).ToString();

            cmd.Parameters.AddWithValue("@phone", Label6.Text).ToString();

            cmd.ExecuteNonQuery();

            Response.Write("done");

             Response.Redirect("WebForm3.aspx");

        }

          }

}   


Vithushalini
College of Technology Jaffna NVQ Level 05 ICT


//insert

        protected void Button1_Click(object sender, EventArgs e)

        {

            SqlConnection con = new SqlConnection("Data Source=comA;Initial Catalog=db001;Integrated Security=True");

            con.Open();

            SqlCommand cmd = new SqlCommand("insert into student values(@stid,@name,@address,@gender,@course)", con);

            cmd.Parameters.AddWithValue("@stid", TextBox1.Text.ToString());

            cmd.Parameters.AddWithValue("@name", TextBox2.Text.ToString());

            cmd.Parameters.AddWithValue("@address", TextBox3.Text.ToString());

            if (RadioButton1.Checked == true)

            {

                cmd.Parameters.AddWithValue("@gender", "Male");

            }

            else

            {

                cmd.Parameters.AddWithValue("@gender", "Female");

            }

            cmd.Parameters.AddWithValue("@course", DropDownList1.Text.ToString());

            cmd.ExecuteNonQuery();

 

        }

 

        protected void Button2_Click(object sender, EventArgs e)

        {

 

 

        }

 

        protected void Button2_Click1(object sender, EventArgs e)

        {

            Session["id0"] = TextBox1.Text;

            Session["id1"] = TextBox2.Text;

            Session["id2"] = TextBox3.Text;

            if (RadioButton1.Checked == true)

            {

                Session["id3"] = "Male";

            }

            else

            {

                Session["id3"] = "Female";

            }

 

 

            Session["id4"] = DropDownList1.Text;

 

            Response.Redirect("WebForm2.aspx");

        }

//fetch

        protected void Button3_Click(object sender, EventArgs e)

        {

            SqlConnection con = new SqlConnection("Data Source=comA;Initial Catalog=db001;Integrated Security=True");

            con.Open();

            SqlCommand cmd = new SqlCommand("select*from student where stuid='" + TextBox1.Text + "'", con);

          

            SqlDataReader reader = cmd.ExecuteReader();

            reader.Read();

            if (reader.HasRows)

            {

                TextBox1.Text = reader[0].ToString();

                TextBox2.Text = reader[1].ToString();

                TextBox3.Text = reader[2].ToString();

                if ((string)reader[3] == "male")

                {

                    RadioButton1.Checked = true ;

                }

                else {

                    RadioButton2.Checked = true;

                }

               

                DropDownList1.Text = reader[4].ToString();

            }

        }

//edit

        protected void Button4_Click(object sender, EventArgs e)

        {

            SqlConnection con = new SqlConnection("Data Source=comA;Initial Catalog=db001;Integrated Security=True");

            con.Open();

 

            SqlCommand cmd = new SqlCommand("update student set stuid=@st,name=@name,address=@add,gender=@gender,course=@course where stuid='" + TextBox1.Text + "'", con);

            cmd.Parameters.AddWithValue("@st", TextBox1.Text.ToString());

            cmd.Parameters.AddWithValue("@name", TextBox2.Text.ToString());

            cmd.Parameters.AddWithValue("@add", TextBox3.Text.ToString());

            if (RadioButton1.Checked == true )

            {

                cmd.Parameters.AddWithValue("@gender", "Male");

            }

            else

            {

                cmd.Parameters.AddWithValue("@gender", "Female");

            }

            cmd.Parameters.AddWithValue("@course", DropDownList1.Text.ToString());

            cmd.ExecuteNonQuery();

          

            TextBox1.Text = "";

            TextBox2.Text = "";

            TextBox3.Text = "";

            RadioButton1.Enabled = false;

            RadioButton2.Enabled = false;

            DropDownList1.Text = "";

           

 

           

        }

//Delete

        protected void Button5_Click(object sender, EventArgs e)

        {

            SqlConnection con = new SqlConnection("Data Source=comA;Initial Catalog=db001;Integrated Security=True");

            con.Open();

            SqlCommand cmd = new SqlCommand("delete from student where stuid='" + TextBox1.Text + "'", con);

            cmd.ExecuteNonQuery();

            Response.Write("Done");

        }

    }

}


Post a Comment

1 Comments

  1. Hello there!
    I’m a specialist in web development.
    Web development is a reasonable limit with respect to doing a task as a specialist furthermore accommodating for managing your own liabilities later on. by and large, web development is a particular ability. various immense affiliations need a web engineer for remaining mindful of our business.
    I make a Site shakeelmumtaz, where you can find concerning web development and also about PHP programming.

    ReplyDelete