Daniel Fisher (lennybacon.com)

SOA, DATA & THE WEB

OleDb + DataReader

<%@ Page language="C#" %>
<script language="C#" runat="server">
 private void Page_Load(object sender, System.EventArgs e)
 {
   System.Data.OleDb.OleDbConnection _conn =
    new System.Data.OleDb.OleDbConnection();
   _conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
    "DataSource=D:\\WebRoot\\data\\data.mdb";
   System.Data.OleDb.OleDbCommand _cmd = _conn.CreateCommand();
   _cmd.CommandType = System.Data.CommandType.Text;
   _cmd.CommandText = "SELECT Name FROM Users WHERE ID=1";
   _conn.Open();
   System.Data.OleDb.OleDbDataReader _reader = cmd.ExecuteReader();
   if(_reader.Read())
   {
     this.TextBox1.Text = _reader.GetString(0);
   }
   _reader.Close();
   _conn.Close();
}
</script>
<html>
<body>
<form ID="Form" runat="server">
 <asp:TextBox id="TextBox1" runat="server
"></asp:TextBox>
</form
>
</body>
</html
>

Comments

Write a comment