0% found this document useful (0 votes)
15 views

Database

Uploaded by

krupa pipaliya
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 views

Database

Uploaded by

krupa pipaliya
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/ 7

 Aspx.

cs

using System;

using System.Collections;

using System.Configuration;

using System.Collections.Generic;

using System.Linq;

using System.Data;

using System.Web;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Xml.Linq;

using System.Data.SqlClient;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.Configuration;

using System.Web.Security;

public partial class d1 : System.Web.UI.Page

string constring;

SqlConnection connect;

SqlCommand cmd;

static SqlDataAdapter da;

static DataTable dt = new DataTable();

DataSet ds = new DataSet();

static int recptr = 0;

void showdata()
{

dt.Clear();

da = new SqlDataAdapter("select * from employee", connect);

da.Fill(dt);

txtid.Text = dt.Rows[recptr][0].ToString();

txtname.Text = dt.Rows[recptr][1].ToString();

txtdes.Text = dt.Rows[recptr][2].ToString();

GridView1.DataSource = dt;

GridView1.DataBind();

void refreshdata()

ds.Clear();

da = new SqlDataAdapter("select * from employee", connect);

da.Fill(ds);

protected void Page_Load(object sender, EventArgs e)

constring = WebConfigurationManager.ConnectionStrings["constring"].ConnectionString;

connect = new SqlConnection(constring);

if (!IsPostBack)

refreshdata();

showdata();

connect.Open();

}
protected void btnfirst_Click(object sender, EventArgs e)

recptr = 0;

showdata();

protected void btnprevious_Click(object sender, EventArgs e)

if (recptr > 0)

recptr--;

showdata();

protected void btnnext_Click(object sender, EventArgs e)

if (recptr < dt.Rows.Count - 1)

recptr++;

showdata();

protected void btnlast_Click(object sender, EventArgs e)

recptr = dt.Rows.Count - 1;

showdata();
}

protected void btnclear_Click(object sender, EventArgs e)

txtid.Text = "";

txtname.Text = "";

txtdes.Text = "";

protected void btnadd_Click(object sender, EventArgs e)

string query = "insert into employee values('" + txtid.Text + "','" + txtname.Text + "','" +
txtdes.Text + "')";

cmd = new SqlCommand(query, connect);

int rows = cmd.ExecuteNonQuery();

refreshdata();

showdata();

GridView1.DataBind();

protected void btnupdate_Click(object sender, EventArgs e)

cmd = new SqlCommand("update employee set employeename='" + txtname.Text +


"',designation='" + txtdes.Text + "',where Employeeid=" + txtid.Text, connect);

cmd.ExecuteNonQuery();

refreshdata();

showdata();

GridView1.DataBind();

}}
 Aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="d1.aspx.cs" Inherits="d1"


Debug="true"%>

<!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>

<form id="form1" runat="server">

<asp:Label ID="Label1" runat="server" Text="Employee details"></asp:Label>

<div>

<asp:GridView ID="GridView1" runat="server">

</asp:GridView>

<br />

<asp:Label ID="Label2" runat="server" Text="Employee ID"></asp:Label>

<asp:TextBox ID="txtid" runat="server"></asp:TextBox>

<br />

<asp:Label ID="Label3" runat="server" Text="Employee Name"></asp:Label>

<asp:TextBox ID="txtname" runat="server"></asp:TextBox>

<br />

<asp:Label ID="Label4" runat="server" Text="Designation"></asp:Label>

<asp:TextBox ID="txtdes" runat="server"></asp:TextBox>

<br />

<asp:Button ID="btnfirst" runat="server" Text="&lt;&lt;"

onclick="btnfirst_Click" />

<asp:Button ID="btnprevious" runat="server" Text="&lt;"


onclick="btnprevious_Click" />

<asp:Button ID="btnnext" runat="server" Text="&gt;" onclick="btnnext_Click" />

<asp:Button ID="btnlast" runat="server" Text="&gt;&gt;"

onclick="btnlast_Click" />

<br />

<br />

<br />

<asp:Button ID="btnadd" runat="server" Text="Add" onclick="btnadd_Click" />

<asp:Button ID="btnupdate" runat="server" Text="Update"

onclick="btnupdate_Click" />

<asp:Button ID="btnclear" runat="server" Text="Clear"

onclick="btnclear_Click" />

</div>

</form>

</body>

</html>

 Web config

<configuration>
<connectionStrings>

<add name="constring" connectionString="Data Source=.\


SQLEXPRESS;AttachDbFilename=E:\CSE 5\ASP.net\web\WEB\App_Data\
Student.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />

</connectionStrings>

<system.web>
<compilation debug="true" targetFramework="4.0" />

<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>

You might also like