OleDb + DataSet

<%@ 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;" +
     "Data Source=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";
    System.Data.OleDb.OleDbDataAdapter _adapter =
     new System.Data.OleDb.OleDbDataAdapter();
    _adapter.SelectCommand = _cmd;
    System.Data.DataSet _dataset = new System.Data.DataSet();
    _conn.Open();
    _adapter.Fill(dataset, "UserTable");
    _conn.Close();
    if(_dataset.Tables["UserTable"].Rows.Count>0)
    {
      this.TextBox1.Text =
       _dataset.Tables["UserTable"].Rows[0][0].ToString();
    }
  }
</script>
<html>
<body>
<form ID="Form" runat="server">
 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>

Comments (1) -

  • Eye opening Article! At last somebody who really knows what
    they are talking about and can additionally produce
    exellent material for us the readers. Certainly looking forward to your next posting.
Comments are closed