Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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