UPDATE Query

UPDATE Query
 SQL UPDATE Query is used to modify the existing records in a table. WHERE clause with the UPDATE query to update the selected rows, otherwise all the rows would be affected.

library -   using System.Data.SqlClient;

Syntax:
Update student(table) set name = ' " + TextBox2.Text+ " ' , age =  ' " + TextBox3.Text+ " ' where rn =  ' " + TextBox1.Text+ " ' ;

1. Design

2. Write code on Button_Click3

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection cn;
    SqlCommand cm;
    SqlDataReader dr;
    protected void Page_Load(object sender, EventArgs e)
    {


    }
 protected void Button3_Click(object sender, EventArgs e)
    {
        string cs = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True";
        cn = new SqlConnection(cs);
        cn.Open();
        string k = "Update stu set name = '"+TextBox2.Text+"', age = '"+TextBox3.Text+"' where rn = '"+TextBox1.Text+"'";
        cm = new SqlCommand(k, cn);
        cm.ExecuteNonQuery();

    }

}

Output:






Popular Posts