0% found this document useful (0 votes)
17 views3 pages

Create A Website To Connectivity With SQL Database Connection

It is work related

Uploaded by

jerishavaghela
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Create A Website To Connectivity With SQL Database Connection

It is work related

Uploaded by

jerishavaghela
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

9. Create a Website to Connectivity with SQL Database Connection.

Step 1:- After that create Sql Database

Server Explorer 
Data Connection
Right Click
Create New SQL Server Database
Server Name:- (Give your PC Name\ SQLEXPRESS) 
New Database Name:- db1
OK

Step 2:- Create Table

Server Explorer
Double Click on Database Name
Right Click on Table
Add New Table
Then Create a Table

After that press Ctrl + S than then choose name window open

After that Click on Table


Table Name (stud)
Right Click on Table Name
Show Table Data
Property:

1.label1 id-lbl_No
Text-No

2.label2 id-lbl_Name
Text-Name

3.label3 id-lbl_City
Text-City

4.textbox1 id-txt_No

5.textbox2 id-txt_Name

6.textbox3 id-txt_City

7.button1 id-btn_Insert
Text-lnsert

8.button2 id-btn_Clear
Text-Clear
Coding:

Connection path Selecting

Server Explorer
Right Click on server name
Properties
Go to properties window in that connection string select the path a ctrl + C and paste on
pathset

using System.Data.SqlClient;

Double Click on Insert button and write this codding

public partial class _Default : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btn_Insert_Click(object sender, EventArgs e)
{
String x = "Data Source=DESKTOP-JJDLBAB\\SQLEXPRESS;Initial Catalog=db1;Integrated
Security=True;Pooling=False";
SqlConnection con = new SqlConnection(x);
con.Open();
String sql="insert into stud values(@no,@name,@city)";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("@no", txt_No.Text);
cmd.Parameters.AddWithValue("@name", txt_Name.Text);
cmd.Parameters.AddWithValue("@city", txt_City.Text);
int ans = cmd.ExecuteNonQuery();
if (ans > 0)
Response.Write("<p>Detalils of<u><b>" + txt_Name.Text + "</b></u>Added to Database");
else
Response.Write("<p>Problem Inserting record");
con.Close();
}
protected void btn_Clear_Click(object sender, EventArgs e)
{
txt_No.Text = "";
txt_Name.Text = "";
txt_City.Text = "";
txt_No.Focus();
}

Insert The Record and Check the Table Record.

You might also like