Connection Oriented approach

Harshpinder
Posted by Harshpinder under ASP.NET category on | Points: 40 | Views : 1590
default.aspx.cs file
public partial class _Default : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("data source=111;user id=112;password=111;database=s11s");

protected void Button1_Click(object sender, EventArgs e)
{
//Connection Oriented Approach on button click
conn.Open();
SqlCommand cmd = new SqlCommand("select * from student where Regid='" + TextBox1.Text + "'", conn);
SqlDataReader ds = cmd.ExecuteReader();


GridView2.DataSource = ds;
GridView2.DataBind();
conn.Close();


}
}


asp code.......................

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

<!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>assignment2</title>
</head>
<body bgcolor="#993333">
<form id="form1" runat="server">
<div align="center" style="background-color: #808080; font-family: 'Times New Roman', Times, serif; font-size: large; font-weight: bold; font-style: italic; color: #800000">

CONNECTION ORIENTED APPROACH</div>
<center> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Search" />
<br />
<br />
<asp:GridView ID="GridView2" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None">
<RowStyle BackColor="#E3EAEB" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView></center>
<br />

</form>
</body>
</html>

Comments or Responses

Login to post response