1: Open visual studio 2005 and from FILE select NEW-> WebSite, then from pop-menu select asp.net
website (Note: Language must be C#) , then press OK.
2: Now create three textboxes from the toolbox , to remove ambiguity I am using default name for that textboxes and that should be textbox1,textbox2 & textbox3. And also drag & drop the button to the asp.net application.
3: Meanwhile, Open SQL SERVER Management studio 2005 and open adventureworks(or you can create your own database by the Sql command CREATE DATABASE database_name), but here I am using AdventureWorks database.
4: Then create table by clicking right mouse button and form three column, Name them according to your requirement , for your information only I used EID,name,Address. And click save button, then you’ll get a pop up menu where you have to enter the Table Name, for this example I used students.
5: Now Come Back to Visual studio Application and write the following code in the button_click event.
Code:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection myConn = new SqlConnection();
myConn.ConnectionString = “Connection string(See Below for this — )COPY PASTE HERE“;
myConn.Open();
string strqry = “Insert into students values (” + TextBox1.Text +
“,’” + TextBox2.Text + “‘,’” + TextBox3.Text + “‘)”;
SqlCommand myCom = new SqlCommand(strqry, myConn);
int numrow = myCom.ExecuteNonQuery();
myConn.Close();
}
Bookmarks