Daniel Fisher (lennybacon.com)

SOA, DATA & THE WEB

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

Write a comment