theme

" जीतने वाले छोड़ते नहीं और छोड़ने वाले जीतते नही "

.NET

ADO.NET IN CONNECTED MODE FOR INSERT/UPDATE/DELETE/SEARCH

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con=new SqlConnection(@"Data Source=.\SQLEXPRESS;User Instance=True;AttachDbFilename=C:\Users\TARUN\Documents\Visual Studio 2010\WebSites\datareader\App_Data\dda.mdf;Integrated Security=True;");
con.Open ();

string qry="insert into customer values("+TextBox1.Text+","+"'"+TextBox2.Text+"'"+","+"'"+TextBox3.Text+"'"+")";

SqlCommand com=new SqlCommand(qry,con);
int x=com.ExecuteNonQuery();
if (x==1)
Label4.Text ="Record Inserted";
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;User Instance=True;AttachDbFilename=C:\Users\TARUN\Documents\Visual Studio 2010\WebSites\datareader\App_Data\dda.mdf;Integrated Security=True;");
con.Open();

string qry = "delete from customer where custid=" + TextBox1.Text;

SqlCommand com = new SqlCommand(qry, con);
int x = com.ExecuteNonQuery();
if (x == 1)
Label4.Text = "Record Deleted";
else
Label4.Text = "Record not found";
}
protected void Button4_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;User Instance=True;AttachDbFilename=C:\Users\TARUN\Documents\Visual Studio 2010\WebSites\datareader\App_Data\dda.mdf;Integrated Security=True;");
con.Open();

string qry = "Select * from customer where custid=" + TextBox1.Text;

SqlCommand com = new SqlCommand(qry, con);
SqlDataReader dr = com.ExecuteReader();
dr.Read();
TextBox2.Text = dr["custnm"].ToString();
TextBox3.Text = dr["addr"].ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;User Instance=True;AttachDbFilename=C:\Users\TARUN\Documents\Visual Studio 2010\WebSites\datareader\App_Data\dda.mdf;Integrated Security=True;");
con.Open();

//update customer set custnm='kamal',addr='delhi' where custid=101
string qry = "update customer set custnm=" + "'" + TextBox2.Text + "'" + "," + "addr=" + "'" + TextBox3.Text + "'" + "where custid=" + TextBox1.Text;

SqlCommand com = new SqlCommand(qry, con);
int x = com.ExecuteNonQuery();
if (x == 1)
Label4.Text = "Record Updated";
}
}

No comments:

Post a Comment