Asp Page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="DataBaseProg.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div >
<asp:Label ID="Label1" runat="server" Text="Eno"></asp:Label><asp:TextBox ID="Txt1" runat="server"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="EName"></asp:Label><asp:TextBox ID="Txt2" runat="server"></asp:TextBox><br />
<asp:Label ID="Label3" runat="server" Text="Age"></asp:Label><asp:TextBox ID="Txt3" runat="server"></asp:TextBox><br />
<asp:Label ID="Label4" runat="server" Text="Gender"></asp:Label><asp:TextBox ID="Txt4" runat="server"></asp:TextBox><br />
<asp:Label ID="Label5" runat="server" Text="DoJ"></asp:Label><asp:TextBox ID="Txt5" runat="server"></asp:TextBox><br />
<asp:Label ID="Label6" runat="server" Text="Salary"></asp:Label><asp:TextBox ID="Txt6" runat="server"></asp:TextBox><br />
<asp:Label ID="Label7" runat="server" Text=""></asp:Label>
</div>
<div>
<asp:Button ID="Button1" runat="server" Text="Save" OnClick="Button1_Click" /><asp:Button ID="Button2" runat="server" Text="Clear" OnClick="Button2_Click" /></div>
</div>
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="eno" HeaderText="eno" SortExpression="eno" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="age" HeaderText="age" SortExpression="age" />
<asp:BoundField DataField="gender" HeaderText="gender" SortExpression="gender" />
<asp:BoundField DataField="doj" HeaderText="doj" SortExpression="doj" />
<asp:BoundField DataField="sal" HeaderText="sal" SortExpression="sal" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:JagadeeshConnectionString2 %>" SelectCommand="SELECT * FROM [emp3]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
Cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace DataBaseProg
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string conn = "Data Source=JAGADEESH\\SQLEXPRESS;Initial Catalog=Jagadeesh;User ID=sa;Password=9030302074";
String qry = "insert into emp3(eno,name,age,gender,doj,sal) values (@eno,@name,@age,@gender,@doj,@sal)";
using (SqlConnection con = new SqlConnection( conn))
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand(qry, con);
cmd.Parameters.AddWithValue("@eno",Txt1.Text);
cmd.Parameters.AddWithValue("@name",Txt2.Text);
cmd.Parameters.AddWithValue("@age", Txt3.Text);
cmd.Parameters.AddWithValue("@gender", Txt4.Text);
cmd.Parameters.AddWithValue("@doj", Txt5.Text);
cmd.Parameters.AddWithValue("@sal", Txt6.Text);
cmd.ExecuteNonQuery();
Label7.Text = "Data inserted";
}
catch(Exception ex)
{
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string conn = "Data Source=JAGADEESH\\SQLEXPRESS;Initial Catalog=Jagadeesh;User ID=sa;Password=9030302074";
String qry = "Select * from emp3";
using (SqlConnection con = new SqlConnection(conn))
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand(qry, con);
cmd.ExecuteNonQuery();
}
catch ( Exception ex)
{
}
}
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="DataBaseProg.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div >
<asp:Label ID="Label1" runat="server" Text="Eno"></asp:Label><asp:TextBox ID="Txt1" runat="server"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="EName"></asp:Label><asp:TextBox ID="Txt2" runat="server"></asp:TextBox><br />
<asp:Label ID="Label3" runat="server" Text="Age"></asp:Label><asp:TextBox ID="Txt3" runat="server"></asp:TextBox><br />
<asp:Label ID="Label4" runat="server" Text="Gender"></asp:Label><asp:TextBox ID="Txt4" runat="server"></asp:TextBox><br />
<asp:Label ID="Label5" runat="server" Text="DoJ"></asp:Label><asp:TextBox ID="Txt5" runat="server"></asp:TextBox><br />
<asp:Label ID="Label6" runat="server" Text="Salary"></asp:Label><asp:TextBox ID="Txt6" runat="server"></asp:TextBox><br />
<asp:Label ID="Label7" runat="server" Text=""></asp:Label>
</div>
<div>
<asp:Button ID="Button1" runat="server" Text="Save" OnClick="Button1_Click" /><asp:Button ID="Button2" runat="server" Text="Clear" OnClick="Button2_Click" /></div>
</div>
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="eno" HeaderText="eno" SortExpression="eno" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="age" HeaderText="age" SortExpression="age" />
<asp:BoundField DataField="gender" HeaderText="gender" SortExpression="gender" />
<asp:BoundField DataField="doj" HeaderText="doj" SortExpression="doj" />
<asp:BoundField DataField="sal" HeaderText="sal" SortExpression="sal" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:JagadeeshConnectionString2 %>" SelectCommand="SELECT * FROM [emp3]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
Cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace DataBaseProg
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string conn = "Data Source=JAGADEESH\\SQLEXPRESS;Initial Catalog=Jagadeesh;User ID=sa;Password=9030302074";
String qry = "insert into emp3(eno,name,age,gender,doj,sal) values (@eno,@name,@age,@gender,@doj,@sal)";
using (SqlConnection con = new SqlConnection( conn))
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand(qry, con);
cmd.Parameters.AddWithValue("@eno",Txt1.Text);
cmd.Parameters.AddWithValue("@name",Txt2.Text);
cmd.Parameters.AddWithValue("@age", Txt3.Text);
cmd.Parameters.AddWithValue("@gender", Txt4.Text);
cmd.Parameters.AddWithValue("@doj", Txt5.Text);
cmd.Parameters.AddWithValue("@sal", Txt6.Text);
cmd.ExecuteNonQuery();
Label7.Text = "Data inserted";
}
catch(Exception ex)
{
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string conn = "Data Source=JAGADEESH\\SQLEXPRESS;Initial Catalog=Jagadeesh;User ID=sa;Password=9030302074";
String qry = "Select * from emp3";
using (SqlConnection con = new SqlConnection(conn))
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand(qry, con);
cmd.ExecuteNonQuery();
}
catch ( Exception ex)
{
}
}
}
}
}
No comments:
Post a Comment