using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace storprocedure00
{
public partial class storedproc : [Link]
{
SqlConnection con = new SqlConnection("data source=DESKTOP-AD5CCNP\\
SQLEXPRESS; initial catalog=aktest66; integrated security=true");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack )
{
Show();
Showcountry();
}
public void Show()
{
[Link]();
SqlCommand cmd = new SqlCommand("tbl_join", con);
[Link] = [Link];
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
[Link](dt);
[Link]();
[Link] = dt;
[Link]();
}
public void Showcountry()
{
try
{
[Link]();
SqlCommand cmd = new SqlCommand("usp_tbl_country", con);
[Link] = [Link];
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
[Link](dt);
[Link]();
[Link] = "country_id";
[Link] = "country_name";
[Link] = dt;
[Link]();
[Link](0, new ListItem("--select--", "0"));
}
catch (Exception ex)
{
throw ex;
}
}
protected void btnsubmit_Click(object sender, EventArgs e)
{
string pp = ""; // loop ki vlues ko store krne ke liye ek string
variavle le rhe hain
for (int i = 0; i < 6; i++)
{
if ([Link][i].Selected == true)
{
pp += [Link][i].Text + ",";
}
}
pp = [Link](',');
if ([Link] == "Submit")
{
[Link]();
SqlCommand cmd = new SqlCommand("stuin", con);
[Link] = [Link];
[Link]("@name", [Link]);
[Link]("@gender", [Link]);
[Link]("@country", [Link]);
[Link]("@hobbies", pp );
[Link]();
[Link]();
Show();
[Link] = "";
[Link]();
[Link] = "0";
[Link]();
}
else if (btnsubmit .Text =="Update")
{
[Link]();
SqlCommand cmd = new SqlCommand("stuupdate", con);
[Link] = [Link];
[Link]("@name", [Link]);
[Link]("@gender", [Link]);
[Link]("@country", [Link]);
[Link]("@hobbies", pp );
[Link]("@argu_id", ViewState["abc"]);
[Link]();
[Link]();
Show();
[Link] = "";
[Link]();
[Link] = "0";
[Link]();
}
protected void grdvu_RowCommand(object sender, GridViewCommandEventArgs e)
{
if([Link] =="D")
{
[Link]();
SqlCommand cmd = new SqlCommand("studelete", con);
[Link] = [Link];
[Link]("@argu_id", [Link]);
[Link]();
[Link]();
Show();
}
else if ([Link] =="E")
{
[Link]();
SqlCommand cmd = new SqlCommand("stuedit", con);
[Link] = [Link];
[Link]("@argu_id", [Link]);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
[Link](dt);
[Link]();
[Link] = [Link][0]["Name"].ToString();
[Link] = [Link][0]["Gender"].ToString();
[Link] = [Link][0]["Country"].ToString();
[Link] = [Link][0]["Hobbies"].ToString();
ViewState["abc"] = [Link];
[Link] = "Update";
}
}
}
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
create database aktest66
use aktest66
create table tbl_employee
(id int primary key identity(1,1),
Name varchar(90),
Gender int,
Country int,
Hobbies varchar(90))
select*from tbl_employee join tblcountry on Country=country_id
select*from tblcountry
create table tblcountry
(country_id int primary key identity(1,1),
country_name varchar(80))
insert into tblcountry (country_name)values('delhi'),('ahk'),('dhdh')
insert into tblcountry (country_name)values('usa')
insert into tblcountry (country_name)values('uk')
insert into tblcountry (country_name)values('japan')
insert into tblcountry (country_name)values('nepal')
insert into tblcountry (country_name)values('germany')
insert into tblcountry (country_name)values('denmark')
create proc usp_tbl_country
as
begin
select*from tblcountry
end
create proc tbl_join
as
begin
select*from tbl_employee join tblcountry on Country=country_id
end
create proc stuin
@name varchar(90),
@gender int,
@country int,
@hobbies varchar(90)
as
begin
insert into tbl_employee
(Name,Gender ,Country ,Hobbies )values(@name,@gender,@country,@hobbies)
end
create proc stuupdate
@name varchar(90),
@gender int ,
@country int,
@hobbies varchar(90),
@argu_id int
as
begin
update tbl_employee set Name =@name , Gender =@gender ,Country=@country,
Hobbies=@hobbies where id=@argu_id
end
create proc studelete
@argu_id int
as
begin
delete from tbl_employee where id = @argu_id
end
create proc stuedit
@argu_id int
as
begin
select*from tbl_employee where id =@argu_id
end
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border ="1" style ="background-color :darksalmon">
<tr>
<td colspan ="2"><h1>Student Form</h1></td>
</tr>
<tr>
<td>Name:</td>
<td><asp:TextBox ID ="textname" runat
="server"></asp:TextBox></td>
</tr>
<tr>
<td>Gender:</td>
<td><asp:RadioButtonList ID="rblgender" runat ="server"
RepeatColumns="3">
<asp:ListItem Text ="male" Value ="1"></asp:ListItem>
<asp:ListItem Text ="female" Value ="2"></asp:ListItem>
<asp:ListItem Text ="other" Value ="3"></asp:ListItem>
</asp:RadioButtonList></td>
</tr>
<tr>
<td>Country:</td>
<td><asp:DropDownList ID="ddlcountry" runat ="server"
></asp:DropDownList></td>
</tr>
<tr>
<td>Hobbies:</td>
<td><asp:CheckBoxList ID ="cblhobbies" runat ="server" RepeatColumns ="6">
<asp:ListItem Text ="reading" Value="1"></asp:ListItem>
<asp:ListItem Text ="cooking" Value ="2"></asp:ListItem>
<asp:ListItem Text ="dancing" Value="3"></asp:ListItem>
<asp:ListItem Text ="singing" Value="4"></asp:ListItem>
<asp:ListItem Text ="acting" Value ="5"></asp:ListItem>
<asp:ListItem Text ="reading" Value
="6"></asp:ListItem></asp:CheckBoxList></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="btnsubmit" runat ="server" Text ="Submit"
OnClick ="btnsubmit_Click" /></td>
</tr>
<tr>
<td></td>
<td><asp:GridView ID ="grdvu" runat ="server" Text="Show"
AutoGenerateColumns ="false" OnRowCommand="grdvu_RowCommand" >
<Columns>
<asp:TemplateField HeaderText ="Student id" >
<ItemTemplate >
<%#Eval("id") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Student Name" >
<ItemTemplate >
<%#Eval("Name") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Student Gender" >
<ItemTemplate >
<%#Eval("Gender").ToString() =="1" ?
"male":Eval ("Gender").ToString ()=="2"?"female" :"other" %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Student Country" >
<ItemTemplate >
<%#Eval("country_name") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Student Hobbies" >
<ItemTemplate >
<%#Eval("Hobbies") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate >
<asp:LinkButton ID="btndelete" runat ="server"
Text ="Delete" CommandArgument =' <%#Eval("id") %>' CommandName
="D"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate >
<asp:LinkButton ID="btnedit" runat ="server" Text
="Edit" CommandArgument =' <%#Eval("id") %>' CommandName ="E"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView></td>
</tr>
</table>
</div>
</form>
</body>
</html>