Create A Website To Connectivity With SQL Database Connection
Create A Website To Connectivity With SQL Database Connection
Server Explorer
Data Connection
Right Click
Create New SQL Server Database
Server Name:- (Give your PC Name\ SQLEXPRESS)
New Database Name:- db1
OK
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
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:
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;
}
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();
}