<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
string ConnectionString = Convert.ToString(ConfigurationSettings.AppSettings["AccessConnectString"]);
string CommandText = "SELECT * FROM Publisher";
OleDbConnection myConnection = new OleDbConnection(ConnectionString);
OleDbCommand myCommand = new OleDbCommand(CommandText, myConnection);
OleDbDataAdapter myAdapter = new OleDbDataAdapter();
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>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="myGrid" runat="server"></asp:DataGrid>
</form>
</body>
</html>
File:
<configuration>
<appSettings>
<add key="AccessConnectString"
value="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Books.mdb;" />
</appSettings>
</configuration>
|