<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>test sql server connection</title>
</head>
<body>
<h4>first example:listing data from a SQLServer table</h4>
<asp:DataGrid id="dgUserList"
runat="server"
GridLines="None"
BackColor="LightBlue"
CellPadding="5"
CellSpacing="5"
BorderWidth="2"
BorderColor="Black"
ToolTip="Show all the userinfo"/>
</body>
</html>
<script language="C#" runat="server">
private void Page_Load(Object sender, EventArgs e) {
String strConnection="server=(local);database=users;uid=test;pwd=test;";
SqlConnection objConnection=new SqlConnection(strConnection);
String strSQL="SELECT * FROM userinfo";
SqlCommand objCommand=new SqlCommand(strSQL,objConnection);
objConnection.Open();
dgUserList.DataSource=objCommand.ExecuteReader();
dgUserList.DataBind();
objConnection.Close();
}
</script>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>test sql server connection</title>
</head>
<body>
<h4>first example:listing data from a SQLServer table</h4>
<asp:DataGrid id="dgUserList"
runat="server"
GridLines="None"
BackColor="LightBlue"
CellPadding="5"
CellSpacing="5"
BorderWidth="2"
BorderColor="Black"
ToolTip="Show all the userinfo"/>
</body>
</html>
<script language="C#" runat="server">
private void Page_Load(Object sender, EventArgs e) {
String strConnection="server=(local);database=users;uid=test;pwd=test;";
SqlConnection objConnection=new SqlConnection(strConnection);
String strSQL="SELECT * FROM userinfo";
SqlCommand objCommand=new SqlCommand(strSQL,objConnection);
objConnection.Open();
dgUserList.DataSource=objCommand.ExecuteReader();
dgUserList.DataBind();
objConnection.Close();
}
</script>