beuti of the nature

feel all about.....

Friday, June 26, 2015

sql connection

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; using System.Data; using System.Web.Configuration; public partial class DefaultPerson : System.Web.UI.Page { SqlConnection con = new SqlConnection( WebConfigurationManager.ConnectionStrings["PersonConnectionString"].ConnectionString); protected void Page_Load(object sender, EventArgs e) { } protected void Button3_Click(object sender, EventArgs e) { //SqlConnection db = new SqlConnection("Data Source=localhost;Initial Catalog=Person;Integrated Security=True;providerName=System.Data.SqlClient"); SqlDataAdapter ad = new SqlDataAdapter("select * from [Person].[dbo].[Person_deatails] where [person_id]='" + TextBox3.Text + "'", con); DataTable dt=new DataTable(); ad.Fill(dt); TextBox4.Text=dt.Rows[0][1].ToString(); } protected void Button1_Click(object sender, EventArgs e) { con.Open(); //SqlDataAdapter ad = new SqlDataAdapter("insert into [Person].[dbo].[Person_deatails] (person_id,preson_fname,preson_lname) values ('" + Convert.ToInt16(TextBox5.Text) + "','" + TextBox6.Text + "','" + TextBox7.Text + "')", con); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = "insert into [Person].[dbo].[Person_deatails] (person_id,preson_fname,person_lname) values ('" + Convert.ToInt16(TextBox5.Text) + "','" + TextBox6.Text + "','" + TextBox7.Text + "')"; //DataTable dt = new DataTable(); //ad.Fill(dt); //TextBox4.Text = dt.Rows[0][1].ToString(); int rowsAffected = cmd.ExecuteNonQuery(); if (rowsAffected == 1) { Label1.Text = "OK"; } else { Label1.Text = "Fail"; } } protected void Button4_Click(object sender, EventArgs e) { con.Open(); SqlCommand cmd = new SqlCommand("UPDATE [Person_deatails] SET preson_fname='" + TextBox4.Text + "' where [person_id]='" + TextBox3.Text + "' ", con); cmd.ExecuteNonQuery(); } }

No comments:

Post a Comment

There was an error in this gadget