Wednesday, August 6, 2014

With only ASPX (asp.net) code, connect to SQL server database, and list table contents with query (no compilation or dll needed)

Mypage.aspx


<html xmlns="http://www.w3.org/1999/xhtml">
<head><title></title></head>
<body>
    <form id="form1" runat="server">
        <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" EnableModelValidation="True" AllowPaging="True" AutoGenerateColumns="true">            
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:maniConnectionString %>" SelectCommand="SELECT * FROM [Server_Capacity_1]"></asp:SqlDataSource>
    </form>
</body>
</html>
Sample web.config connecting to SQL Server


<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="MyConnectionString" connectionString="Data Source=myservername.com;Initial Catalog=MyDBName;Persist Security Info=True;User ID=myuserid;Password=myPassword"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

No comments:

Turn on Windows 11 Fast Boot

If windows starting is slow, to enable windows 11 fast startup/boot,  Press Windows + R, type powercfg.cpl, and hit Enter.  This will direct...