3-Tire Architecture in asp.net with C#
Insert Data
Generate Report
ADD Class file and Report
ASPX FILE
<%@ Page Language="C#"
AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" MaintainScrollPositionOnPostback="true" EnableEventValidation="false" %>
<%@ Register Assembly="CrystalDecisions.Web,
Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR"
%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body bgcolor="#3399CC">
<form id="form1" runat="server">
<div>
<asp:Label ID="Label19" runat="server" ForeColor="White" Text="Label"></asp:Label>
<table border="1" bordercolor="white">
<tr>
<td>
<h1 class="stylee">REGISTER
FORM</h1>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" ForeColor="White"
runat="server"
Text="employee
name"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
</td><td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ErrorMessage="please
enter company name" ForeColor="Blue"
ControlToValidate="TextBox1">
</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" ForeColor="White"
runat="server"
Text="employee
address"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2"
runat="server"
TextMode="MultiLine"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2"
runat="server"
ErrorMessage="please
enter company address" ForeColor="Blue"
ControlToValidate="TextBox2"
>
</asp:RequiredFieldValidator></td>
</tr>
<%--<tr>
<td>
<asp:Label
ID="Label3" ForeColor="White" runat="server"
Text="company man_address"></asp:Label>
</td>
<td>
<asp:TextBox
ID="TextBox3" runat="server"
TextMode="MultiLine"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3"
runat="server" ErrorMessage="please enter company address"
ForeColor="Blue"
ControlToValidate="TextBox2" >
</asp:RequiredFieldValidator></td>
</tr>--%>
<tr>
<td>
<asp:Label ID="Label4" ForeColor="White"
runat="server"
Text="employee
state"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1"
runat="server"
style="height: 22px"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True"
DataTextField="statename"
DataValueField="statename"
>
</asp:DropDownList>
<td>
<%--<asp:RequiredFieldValidator
ID="RequiredFieldValidator8" runat="server"
ErrorMessage="please enter company address" ForeColor="Red"
ControlToValidate="TextBox4" >
</asp:RequiredFieldValidator></td>--%>
</tr>
<tr>
<td>
<asp:Label ID="Label5" ForeColor="White"
runat="server"
Text="employee
city"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList2"
runat="server"
AutoPostBack="True"
DataTextField="city"
DataValueField="city"
>
</asp:DropDownList>
</td>
<td>
<%--<asp:RequiredFieldValidator
ID="RequiredFieldValidator4" runat="server"
ErrorMessage="please enter city" ForeColor="Red"
ControlToValidate="TextBox5" >
</asp:RequiredFieldValidator></td>--%>
</tr>
<tr>
<td>
<asp:Label ID="Label6" ForeColor="White"
runat="server"
Text="employee
email"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox6"
runat="server"></asp:TextBox>
</td>
<td>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1"
runat="server"
ForeColor="Blue"
ErrorMessage="invalid
email" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ControlToValidate="TextBox6">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label7" ForeColor="White"
runat="server"
Text="employee
salary"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox7"
runat="server"
></asp:TextBox>
</td>
<td>
<%--<asp:RegularExpressionValidator
ID="RegularExpressionValidator2" runat="server"
ValidationExpression="http(s)?://([\w-]+\.)+[\w-]+(/[\w-
./?%&=]*)?"
ForeColor="Blue" ControlToValidate="TextBox7" ErrorMessage="Input valid Internet
URL!">
</asp:RegularExpressionValidator>--%>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label14"
ForeColor="White"
runat="server"
Text="employee
photos"></asp:Label>
</td>
<td>
<asp:FileUpload ID="FileUpload1"
runat="server"
/>
</td>
<td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator8"
runat="server"
ErrorMessage="enter
logo" ForeColor="Blue" ControlToValidate="FileUpload1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server"
ForeColor="White"
Text="Gender"></asp:Label>
</td>
<td>
<%--<asp:RadioButtonList ForeColor="White"
ID="RadioButtonList1" runat="server">
<asp:ListItem Text="male"
Value="0"></asp:ListItem>
<asp:ListItem Text="female"
Value="1"></asp:ListItem>
</asp:RadioButtonList>--%>
<asp:RadioButton ID="RadioButton1" ForeColor="White" Text="male" runat="server" GroupName="x" />
<asp:RadioButton ID="RadioButton2"
ForeColor="White"
Text="female"
runat="server"
GroupName="x"
/>
</td>
<td>
<%--<asp:RequiredFieldValidator
ID="RequiredFieldValidator3"
runat="server" ErrorMessage="please check Gender"
ControlToValidate="RadioButtonList1"></asp:RequiredFieldValidator>--%>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label8" runat="server" ForeColor="White" Text="Hobbys"></asp:Label>
</td>
<td>
<asp:CheckBoxList ForeColor="White"
ID="CheckBoxList1"
runat="server">
<asp:ListItem Text="Reading
book"></asp:ListItem>
<asp:ListItem Text="coock"></asp:ListItem>
<asp:ListItem Text="watch
movie"></asp:ListItem>
</asp:CheckBoxList>
</td>
<%--<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4"
runat="server" ErrorMessage="please checked hobbys"
ControlToValidate="CheckBoxList1"></asp:RequiredFieldValidator>
</td>--%>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="Button1"
runat="server"
Text="insert"
onclick="Button1_Click"
/>
<asp:Button ID="Button2"
runat="server"
Text="update"
CausesValidation="False"
onclick="Button2_Click"
Visible="false"
/>
<asp:Button ID="Button3"
runat="server"
Text="Cleare"
CausesValidation="False"
onclick="Button3_Click"
/>
</td>
</tr>
</table>
<asp:Button ID="Button4" runat="server" CausesValidation="false" Text="create crystalreport"
onclick="Button4_Click" />
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
AutoDataBind="true"
/>
<asp:GridView ID="GridView1" ForeColor="White" runat="server"
AutoGenerateColumns="False" DataKeyNames="emp_id"
onrowediting="GridView1_RowEditing" onrowdeleting="GridView1_RowDeleting">
<Columns>
<asp:TemplateField HeaderText="id" Visible="false">
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%#Eval("emp_id")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="emp_nm">
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%#Eval("emp_nm")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="emp_add">
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%#Eval("emp_add")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="state">
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%#Eval("state")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="city">
<ItemTemplate>
<asp:Label ID="Label13" runat="server" Text='<%#Eval("city")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="emp_email">
<ItemTemplate>
<asp:Label ID="Label14" runat="server" Text='<%#Eval("emp_email")
%>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="emp_salary">
<ItemTemplate>
<asp:Label ID="Label15" runat="server" Text='<%#Eval("emp_salary")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="emp_nm">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Width="60px"
Height="60px"
ImageUrl='<%#Eval("emp_photo")
%>' />
<asp:Label ID="Label18" runat="server" Text='<%#Eval("emp_photo")
%>' Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="gender">
<ItemTemplate>
<asp:Label ID="Label16" runat="server" Text='<%#Eval("gender")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="hobby">
<ItemTemplate>
<asp:Label ID="Label17" runat="server" Text='<%#Eval("hobby")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="edit">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="edit" CausesValidation="False">edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="delete">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" CommandName="delete" CausesValidation="false" runat="server">delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Report">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" OnClick="select" CausesValidation="false" ImageUrl="~/imagegoogle.jpeg" Height="30px"
Width="30px"
runat="server"
/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
ASPX.CS FILE
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data;
using
System.Data.SqlClient;
using System.IO;
using
System.Collections;
using
CrystalDecisions.CrystalReports.Engine;
using
CrystalDecisions.Shared;
public partial class _Default : System.Web.UI.Page
{
DataClassesDataContext
dc = new DataClassesDataContext();
protected void Page_Load(object
sender, EventArgs e)
{
grid();
if
(!IsPostBack)
{
Bind_ddlstate();
}
}
public void grid()
{
/*var emps =
from myemp in dc.pi_emps
select new
{
};*/
emp_bal
empb = new emp_bal();
DataTable
dt = empb.select();
GridView1.DataSource = dt;
GridView1.DataBind();
}
public void Bind_ddlstate()
{
string
con = @"Data Source=SQLDB;Initial
Catalog=Demo;User ID=Demoh;Password=Demo1@";
SqlConnection
conn = new SqlConnection(con);
conn.Open();
string
q = "select * from pi_statedemo";
DataSet
ds = new DataSet();
SqlDataAdapter
da = new SqlDataAdapter(q,
conn);
da.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("--select--"));
//
DropDownList2.Items.Insert(0, new ListItem("--select--"));
//if
(DropDownList1.SelectedIndex == -1)
//{
// DropDownList2.SelectedIndex = -1;
//}
conn.Close();
}
public void Bind_ddlCity()
{
DropDownList2.Items.Clear();
string
con = @"Data Source=SQLDB;Initial
Catalog=Demo;User ID=Demoh;Password=Demo1@";
SqlConnection
conn = new SqlConnection(con);
conn.Open();
string
q = "select city from pi_citydemo where id
='" + DropDownList1.SelectedIndex + "'";
DataSet
ds = new DataSet();
SqlDataAdapter
da = new SqlDataAdapter(q,
conn);
da.Fill(ds);
DropDownList2.DataSource = ds;
DropDownList2.DataBind();
conn.Close();
}
protected void Button1_Click(object
sender, EventArgs e)
{
emp_bal
empb = new emp_bal();
FileUpload1.SaveAs(Server.MapPath("~/image" + FileUpload1.FileName));
string
ph = "~/image" +
FileUpload1.FileName;
int s =
DropDownList1.SelectedIndex;
int c =
DropDownList2.SelectedIndex;
string
g = null;
if
(RadioButton1.Checked)
{
g = RadioButton1.Text;
}
else
{
g = RadioButton2.Text;
}
string
s1 = string.Empty;
foreach
(ListItem item in
this.CheckBoxList1.Items)
{
if
(item.Selected)
{
s1 += item + ",";
}
}
if
(empb.insert(TextBox1.Text, TextBox2.Text, DropDownList1.SelectedValue, DropDownList2.SelectedValue,
TextBox6.Text, int.Parse(TextBox7.Text),ph, g,
s1) > 0)
{
Label19.Text = "Good One";
}
grid();
clearedata();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs
e)
{
Bind_ddlCity();
}
protected void GridView1_RowEditing(object
sender, GridViewEditEventArgs e)
{
Label
l9 = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label9");
Session["id"]
= l9.Text;
Label
l10 = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label10");
TextBox1.Text = l10.Text;
Label
l11 = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label11");
TextBox2.Text = l11.Text;
Label
l12 = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label12");
DropDownList1.SelectedValue = l12.Text;
Bind_ddlCity();
//Label l13 =
(Label)GridView1.Rows[e.NewEditIndex].FindControl("Label13");
Label
l14 = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label14");
TextBox6.Text = l14.Text;
Label
l15 = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label15");
TextBox7.Text = l15.Text;
Label
l18 = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label18");
Session["photos"]
= l18.Text;
Label
l16 = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label16");
if
(l16.Text.Equals("male"))
{
RadioButton1.Checked = true;
}
else
{
RadioButton2.Checked = true;
}
Label
l17 = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label17");
foreach
(ListItem li in
CheckBoxList1.Items)
{
if
(l17.Text.Contains(li.Text))
{
li.Selected = true;
}
}
grid();
Button2.Visible = true;
Button1.Visible = false;
Button3.Visible = false;
}
protected void Button2_Click(object
sender, EventArgs e)
{
emp_bal
empb = new emp_bal();
//emp_bal
empb = new emp_bal();
string
ph = null;
if
(FileUpload1.HasFile)
{
FileUpload1.SaveAs(Server.MapPath("~/image" + FileUpload1.FileName));
ph = "~/image"
+ FileUpload1.FileName;
}
else
{
ph = Session["photos"].ToString();
}
int s =
DropDownList1.SelectedIndex;
int c =
DropDownList2.SelectedIndex;
string
g = null;
if
(RadioButton1.Checked)
{
g = RadioButton1.Text;
}
else
{
g = RadioButton2.Text;
}
string
s1 = string.Empty;
foreach
(ListItem item in
this.CheckBoxList1.Items)
{
if
(item.Selected)
{
s1 += item + ",";
}
}
if
(empb.update(int.Parse(Session["id"].ToString()), TextBox1.Text,
TextBox2.Text, DropDownList1.SelectedValue, DropDownList2.SelectedValue,
TextBox6.Text, int.Parse(TextBox7.Text), ph, g,
s1) > 0) ;
{
Label19.Text = "good one";
}
grid();
clearedata();
Button1.Visible = true;
Button2.Visible = false;
Button3.Visible = true;
}
protected void GridView1_RowDeleting(object
sender, GridViewDeleteEventArgs e)
{
emp_bal
empb = new emp_bal();
Label
l9 = (Label)GridView1.Rows[e.RowIndex].FindControl("Label9");
string
s = l9.Text;
if
(empb.delete(int.Parse(s)) > 0)
{
Label19.Text = "good one";
}
grid();
}
public void clearedata()
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
DropDownList1.SelectedIndex = -1;
Bind_ddlCity();
RadioButton1.Checked = false;
RadioButton2.Checked = false;
foreach
(ListItem li in
CheckBoxList1.Items)
{
li.Selected = false;
}
}
protected void Button3_Click(object
sender, EventArgs e)
{
clearedata();
}
protected void Button4_Click(object
sender, EventArgs e)
{
string
con = @"Data Source=SQLDB;Initial
Catalog=Demo;User ID=Demoh;Password=Demo1@";
SqlConnection
conn = new SqlConnection(con);
ReportDocument
rd = new ReportDocument();
rd.Load(Server.MapPath("emp_report.rpt"));
empdata
emp = new empdata();
conn.Open();
string
q = "select * from pi_emp";
SqlDataAdapter
adp = new SqlDataAdapter(q,
con);
DataTable
dt = new DataTable();
adp.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow
dr = emp.emp_data.NewRow();
dr["emp_nm"]
= dt.Rows[i]["emp_nm"].ToString();
dr["emp_add"]
= dt.Rows[i]["emp_add"].ToString();
dr["state"]
= dt.Rows[i]["state"].ToString();
dr["city"]
= dt.Rows[i]["city"].ToString();
dr["emp_email"]
= dt.Rows[i]["emp_email"].ToString();
dr["emp_salary"]
= dt.Rows[i]["emp_salary"].ToString();
string
s = Server.MapPath(dt.Rows[i]["emp_photo"].ToString());
FileStream
fs = new FileStream(s,
FileMode.Open, FileAccess.Read);
Byte[]
imge = new byte[fs.Length];
fs.Read(imge, 0, System.Convert.ToInt32(fs.Length));
dr["emp_photo"]
= imge;
dr["gender"]
= dt.Rows[i]["gender"].ToString();
dr["hobby"]
= dt.Rows[i]["hobby"].ToString();
//
dr1["cityname"] = dt.Rows[i]["cityname"].ToString();
//
dr1["sid"] = dt.Rows[i]["sid"].ToString();
//d1.data.Rows.Add(dr);
emp.emp_data.Rows.Add(dr);
//d1.pi_gender.Rows.Add(dr3);
//d1.city.Rows.Add(dr1);
}
rd.SetDataSource(emp);
CrystalReportViewer1.ReportSource = rd;
CrystalReportViewer1.RefreshReport();
}
protected void select(object
sender, ImageClickEventArgs e)
{
ImageButton
imgs = sender as ImageButton;
GridViewRow
r = (GridViewRow)imgs.NamingContainer;
ReportDocument
rd = new ReportDocument();
rd.Load(Server.MapPath("emp_report.rpt"));
empdata
emp = new empdata();
Label
l10 = (Label)r.FindControl("Label10");
Label
l11 = (Label)r.FindControl("Label11");
Label
l12 = (Label)r.FindControl("Label12");
Label
l13 = (Label)r.FindControl("Label13");
Label
l14 = (Label)r.FindControl("Label14");
Label
l15 = (Label)r.FindControl("Label15");
Label
l18 = (Label)r.FindControl("Label18");
Label
l16 = (Label)r.FindControl("Label16");
Label
l17 = (Label)r.FindControl("Label17");
DataRow
dr = emp.emp_data.NewRow();
dr["emp_nm"]
= l10.Text;
dr["emp_add"]
= l11.Text;
dr["state"]
= l12.Text;
dr["city"]
= l13.Text;
dr["emp_email"]
= l14.Text;
dr["emp_salary"]
= l15.Text;
string
ie = l18.Text;
string
s = Server.MapPath(ie);
FileStream
fs = new FileStream(s,
FileMode.Open, FileAccess.Read);
Byte[]
imge = new byte[fs.Length];
fs.Read(imge, 0, System.Convert.ToInt32(fs.Length));
dr["emp_photo"]
= imge;
dr["gender"]
= l16.Text;
dr["hobby"]
= l17.Text;
emp.emp_data.Rows.Add(dr);
ReportDocument report = new
ReportDocument();
report.Load(Server.MapPath("emp_report.rpt"));
report.SetDataSource(emp);
CrystalReportViewer1.ReportSource =
report;
CrystalReportViewer1.RefreshReport();
}
}
BAL CLASS FILE
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Data;
using
System.Data.SqlClient;
using System.IO;
using
System.Collections;
/// <summary>
/// Summary description for emp_bal
/// </summary>
public class emp_bal
{
public emp_bal()
{
//
// TODO: Add constructor logic
here
//
}
public int insert(string
emp_nm, string emp_add, string state, string city, string emp_email, int
emp_salary, string emp_photo, string gender, string
hobby)
{
emp_dal
empd = new emp_dal();
try
{
return
empd.insert(emp_nm, emp_add, state, city, emp_email, emp_salary, emp_photo,
gender, hobby);
}
catch
{
throw;
}
finally
{
empd=null;
}
}
public int update(int
emp_id, string emp_nm, string
emp_add, string state, string
city, string emp_email, int emp_salary, string emp_photo, string gender, string
hobby)
{
emp_dal
empd = new emp_dal();
try
{
return
empd.update(emp_id, emp_nm, emp_add, state, city, emp_email, emp_salary,
emp_photo, gender, hobby);
}
catch{
throw;
}
finally
{
empd=null;
}
}
public int delete(int
emp_id)
{
emp_dal
empd = new emp_dal();
try
{
return
empd.delete(emp_id);
}
catch
{
throw;
}
finally
{
empd = null;
}
}
public DataTable select()
{
emp_dal
empd = new emp_dal();
try
{
return
empd.select();
}
finally
{
empd = null;
}
}
}
DAL CLASS FILE
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Data;
using
System.Data.SqlClient;
using System.IO;
using
System.Collections;
/// <summary>
/// Summary description for emp_dal
/// </summary>
public class emp_dal
{
public emp_dal()
{
//
// TODO: Add constructor logic
here
//
}
public int insert(string
emp_nm, string emp_add, string state, string city, string emp_email, int
emp_salary, string emp_photo, string gender, string
hobby)
{
string
con = @"Data Source=SQLDB;Initial
Catalog=Demo;User ID=Demoh;Password=Demo1@";
SqlConnection
conn = new SqlConnection(con);
conn.Open();
SqlCommand
cmd = new SqlCommand("dbo.pi_insert", conn);
cmd.CommandType = CommandType.StoredProcedure;
try
{
cmd.Parameters.AddWithValue("@emp_nm", emp_nm);
cmd.Parameters.AddWithValue("@emp_add", emp_add);
cmd.Parameters.AddWithValue("@state", state);
cmd.Parameters.AddWithValue("@city", city);
cmd.Parameters.AddWithValue("@emp_email", emp_email);
cmd.Parameters.AddWithValue("@emp_salary", emp_salary);
cmd.Parameters.AddWithValue("@emp_photo", emp_photo);
cmd.Parameters.AddWithValue("@gender", gender);
cmd.Parameters.AddWithValue("@hobby", hobby);
return
cmd.ExecuteNonQuery();
}
catch
{
throw;
}
finally
{
cmd.Dispose();
conn.Dispose();
}
}
public int update(int
emp_id, string emp_nm, string
emp_add, string state, string
city, string emp_email, int emp_salary, string emp_photo, string gender, string
hobby)
{
string con = @"Data
Source=SQLDB;Initial Catalog=Demo;User ID=Demoh;Password=Demo1@";
SqlConnection
conn = new SqlConnection(con);
conn.Open();
SqlCommand
cmd = new SqlCommand("dbo.pi_update", conn);
cmd.CommandType = CommandType.StoredProcedure;
try
{
cmd.Parameters.AddWithValue("@emp_id", emp_id);
cmd.Parameters.AddWithValue("@emp_nm", emp_nm);
cmd.Parameters.AddWithValue("@emp_add", emp_add);
cmd.Parameters.AddWithValue("@state", state);
cmd.Parameters.AddWithValue("@city", city);
cmd.Parameters.AddWithValue("@emp_email", emp_email);
cmd.Parameters.AddWithValue("@emp_salary", emp_salary);
cmd.Parameters.AddWithValue("@emp_photo", emp_photo);
cmd.Parameters.AddWithValue("@gender", gender);
cmd.Parameters.AddWithValue("@hobby", hobby);
return
cmd.ExecuteNonQuery();
}
catch
{
throw;
}
finally
{
cmd.Dispose();
conn.Dispose();
}
}
public int delete(int
emp_id)
{
string
con = @"Data Source=SQLDB;Initial
Catalog=Demo;User ID=Demoh;Password=Demo1@";
SqlConnection
conn = new SqlConnection(con);
conn.Open();
SqlCommand
cmd = new SqlCommand("dbo.pi_delete", conn);
cmd.CommandType = CommandType.StoredProcedure;
try
{
cmd.Parameters.AddWithValue("@emp_id", emp_id);
return
cmd.ExecuteNonQuery();
}
catch
{
throw;
}
finally
{
cmd.Dispose();
conn.Dispose();
}
}
public DataTable select()
{
string
con = @"Data Source=SQLDB;Initial
Catalog=Demo;User ID=Demoh;Password=Demo1@";
SqlConnection
conn = new SqlConnection(con);
conn.Open();
SqlCommand
cmd = new SqlCommand("dbo.pi_selectdata", conn);
cmd.CommandType = CommandType.StoredProcedure;
try
{
DataTable
dt = new DataTable();
SqlDataAdapter
da = new SqlDataAdapter(cmd);
da.Fill(dt);
return
dt;
}
catch
{
throw;
}
finally
{
cmd.Dispose();
conn.Dispose();
}
}
}
0 comments :