0% found this document useful (0 votes)
15 views6 pages

VP Lab8

The document contains code for two web forms that perform insert, search, and select operations on a database using ADO.NET. Form 1 inserts a new record into a table and searches the table using stored procedures, displaying the results in a GridView. Form 2 populates a dropdown list with department names from the database and allows selecting a department to associate with another entity.

Uploaded by

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

VP Lab8

The document contains code for two web forms that perform insert, search, and select operations on a database using ADO.NET. Form 1 inserts a new record into a table and searches the table using stored procedures, displaying the results in a GridView. Form 2 populates a dropdown list with department names from the database and allows selecting a department to associate with another entity.

Uploaded by

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

Lab Task

Name:
Ahsan Rasheed
Roll No:
RC-159
Class:
BSCS
Subject:
VP
Section
B
Code:
Form 1
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data.SqlClient;
usingSystem.Data;
namespace WebApplication3
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
SqlConnection conn = newSqlConnection(@"Data Source=LAB06-13\SQL2K14;Integrated
Security=True");
protectedvoidPage_Load(object sender, EventArgs e)
{

DropDownList1.Items.Add("isb");
DropDownList1.Items.Add("rwp");
DropDownList1.Items.Add("pesh");

protectedvoid Button1_Click(object sender, EventArgs e)


{
SqlCommandcmd = newSqlCommand("insertdep", conn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue("@a", TextBox1.Text);
cmd.Parameters.AddWithValue("@b", DropDownList1.SelectedItem.ToString());
conn.Open();
inti = cmd.ExecuteNonQuery();
conn.Close();

if (i>0)
{
Label3.Text = "record Inserted";
Label3.ForeColor = System.Drawing.Color.Green;
}
else
{
Label3.Text = "record not Inserted";
Label3.ForeColor = System.Drawing.Color.Red;
}
}

protectedvoid Button2_Click(object sender, EventArgs e)


{
SqlCommandcmd = newSqlCommand("searchDep", conn);
cmd.CommandType = CommandType.StoredProcedure;
DataTabledt = newDataTable();
SqlDataAdapteradp = newSqlDataAdapter(cmd);
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}

Form 2
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data.SqlClient;
usingSystem.Data;

namespace WebApplication3
{
publicpartialclassWebForm2 : System.Web.UI.Page
{
SqlConnection conn = newSqlConnection(@"Data Source=LAB06-13\SQL2K14;Initial
Catalog=OnetomanySP;Integrated Security=True");
protectedvoidPage_Load(object sender, EventArgs e)
{
SqlCommandcmd = newSqlCommand();
DataTabledt = newDataTable();
SqlDataAdapteradp = newSqlDataAdapter(cmd);
adp.Fill(dt);
DropDownList1.Items.Add("cs");
DropDownList1.Items.Add("se");
DropDownList1.Items.Add("ir");

if (!Page.IsPostBack)
{
SqlCommand cod =newSqlCommand("InsertDep",conn);
DataTabledet = newDataTable();
SqlDataAdapter dap = newSqlDataAdapter(cod);
adp.Fill(dt);
DropDownList2.DataSource = det;
DropDownList2.DataValueField = "depID";
DropDownList2.DataTextField = "depName";
DropDownList2.DataBind();
}
}
}
}

You might also like