<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
string ConnectionString = Convert.ToString(ConfigurationSettings.AppSettings["MSDEConnectString"]);
string CommandText = "SELECT * FROM Publisher";
SqlConnection myConnection = new SqlConnection(ConnectionString);
SqlCommand myCommand = new SqlCommand(CommandText, myConnection);
SqlDataAdapter myAdapter = new SqlDataAdapter();
myAdapter.SelectCommand = myCommand;
DataSet myDataSet = new DataSet();
try {
myConnection.Open();
myAdapter.Fill(myDataSet);
} catch (Exception ex) {
throw (ex);
} finally {
myConnection.Close();
}
myGrid.DataSource = myDataSet;
myGrid.DataBind();
}
</script>
<html>
<body>
<form runat="server">
<asp:DataGrid id="myGrid" runat="server"></asp:DataGrid>
</form>
</body>
</html>
File: Web.config
<configuration>
<appSettings>
<add key="MSDEConnectString"
value="server=(local)\YourDatabase;database=Books;uid=YourID;pwd=letmein;" />
</appSettings>
</configuration>
|