KEMBAR78
Codeofdatabase | TXT
public partial class _Default : System.Web.UI.Page
{ SqlConnection con=new SqlConnection("Data Source=kol-11102-srvmr; Initial
Catalog=Student_s1; User ID = sa; Password = niit@123");
    protected void Page_Load(object sender, EventArgs e)
    {
         if (!IsPostBack)
             Student_Detail();
    }
    public void Student_Detail()
    {
         con.Open();
         SqlCommand cmd = new SqlCommand("select Student_Id from Student_Detail
", con);
         SqlDataAdapter ad = new SqlDataAdapter(cmd);
         DataTable dt = new DataTable();
         ad.Fill(dt);
         DropDownList1.Items.Clear();
         DropDownList1.DataSource = dt;
         DropDownList1.DataTextField = "Student_Id";
         DropDownList1.DataBind();

     }

    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = "Data Source=kol-11102-srvmr; Initial
Catalog=Student_s1; User ID = sa; Password = niit@123";
        con.Open();
        SqlCommand cmd = new SqlCommand("update Student_Detail set
S_Name='"+TextBox1.Text+"',Course='"+TextBox2.Text+"',Address='"+TextBox3.Text+"
',Phon_no='"+TextBox4.Text+"' where Student_Id='"+DropDownList1.Text+"'",con);
        cmd.ExecuteNonQuery();

     }
     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs
e)
     {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = "Data Source=kol-11102-srvmr; Initial
Catalog=Student_s1; User ID = sa; Password = niit@123";
        con.Open();
        SqlCommand cmd = new SqlCommand("select* from Student_Detail where
Student_Id ='" + DropDownList1.Text + "'", con);



          SqlDataReader dr = cmd.ExecuteReader();
          dr.Read();

          if (dr.HasRows)
          {
              TextBox5.Text = dr["Student_Id"].ToString();
              TextBox1.Text= dr["S_Name"].ToString();
              TextBox2.Text= dr["Course"].ToString();
              TextBox3.Text= dr["Address"].ToString();
              TextBox4.Text = dr["Phon_no"].ToString();


          }

      }

     protected void Button2_Click(object sender, EventArgs e)
{

        SqlConnection con = new SqlConnection();
        con.ConnectionString = "Data Source=kol-11102-srvmr; Initial
Catalog=Student_s1; User ID = sa; Password = niit@123";
        con.Open();
        SqlCommand cmd = new SqlCommand("insert into Student_Detail
values('"+DropDownList1.Text+"','"+TextBox1.Text + "','" + TextBox2.Text + "','"
+ TextBox3.Text + "','" + TextBox4.Text + "')", con);
        cmd.ExecuteNonQuery();
        TextBox5.Text = "";
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";

    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = "Data Source=kol-11102-srvmr; Initial
Catalog=Student_s1; User ID = sa; Password = niit@123";
        con.Open();
        SqlCommand cmd = new SqlCommand("Delete Student_Detail where
Student_Id='" + DropDownList1.Text + "'", con);
        cmd.ExecuteNonQuery();
        TextBox5.Text = "";
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
    }
    protected void Button4_Click(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection();
        con.ConnectionString = "Data Source=kol-11102-srvmr; Initial
Catalog=Student_s1; User ID = sa; Password = niit@123";
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from Student_Detail where
Student_Id='" + DropDownList1.Text + "'", con);
        SqlDataAdapter ad = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        ad.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        TextBox5.Text = "";
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";

    }
}

Codeofdatabase

  • 1.
    public partial class_Default : System.Web.UI.Page { SqlConnection con=new SqlConnection("Data Source=kol-11102-srvmr; Initial Catalog=Student_s1; User ID = sa; Password = niit@123"); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) Student_Detail(); } public void Student_Detail() { con.Open(); SqlCommand cmd = new SqlCommand("select Student_Id from Student_Detail ", con); SqlDataAdapter ad = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); ad.Fill(dt); DropDownList1.Items.Clear(); DropDownList1.DataSource = dt; DropDownList1.DataTextField = "Student_Id"; DropDownList1.DataBind(); } protected void Button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = "Data Source=kol-11102-srvmr; Initial Catalog=Student_s1; User ID = sa; Password = niit@123"; con.Open(); SqlCommand cmd = new SqlCommand("update Student_Detail set S_Name='"+TextBox1.Text+"',Course='"+TextBox2.Text+"',Address='"+TextBox3.Text+" ',Phon_no='"+TextBox4.Text+"' where Student_Id='"+DropDownList1.Text+"'",con); cmd.ExecuteNonQuery(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = "Data Source=kol-11102-srvmr; Initial Catalog=Student_s1; User ID = sa; Password = niit@123"; con.Open(); SqlCommand cmd = new SqlCommand("select* from Student_Detail where Student_Id ='" + DropDownList1.Text + "'", con); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { TextBox5.Text = dr["Student_Id"].ToString(); TextBox1.Text= dr["S_Name"].ToString(); TextBox2.Text= dr["Course"].ToString(); TextBox3.Text= dr["Address"].ToString(); TextBox4.Text = dr["Phon_no"].ToString(); } } protected void Button2_Click(object sender, EventArgs e)
  • 2.
    { SqlConnection con = new SqlConnection(); con.ConnectionString = "Data Source=kol-11102-srvmr; Initial Catalog=Student_s1; User ID = sa; Password = niit@123"; con.Open(); SqlCommand cmd = new SqlCommand("insert into Student_Detail values('"+DropDownList1.Text+"','"+TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "')", con); cmd.ExecuteNonQuery(); TextBox5.Text = ""; TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; } protected void Button3_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = "Data Source=kol-11102-srvmr; Initial Catalog=Student_s1; User ID = sa; Password = niit@123"; con.Open(); SqlCommand cmd = new SqlCommand("Delete Student_Detail where Student_Id='" + DropDownList1.Text + "'", con); cmd.ExecuteNonQuery(); TextBox5.Text = ""; TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; } protected void Button4_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = "Data Source=kol-11102-srvmr; Initial Catalog=Student_s1; User ID = sa; Password = niit@123"; con.Open(); SqlCommand cmd = new SqlCommand("select * from Student_Detail where Student_Id='" + DropDownList1.Text + "'", con); SqlDataAdapter ad = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); ad.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); TextBox5.Text = ""; TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; } }