Mega Code Archive

 
Categories / ASP.Net Tutorial / ADO Net Database
 

Use DataTable to read the result set from an OleDbDataAdapter and a DataSet (VB net)

<%@ Page Language="VB" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <script runat="server">    sub Page_Load(Sender as object, e as eventargs)       dim objConn as new OleDbConnection( _             "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _             & "DATA SOURCE=" _             & Server.MapPath("EmployeeDatabase.mdb;"))       dim objCmd as new OleDbDataAdapter("select * from employee", objConn)       dim ds as DataSet = new DataSet()       objCmd.Fill(ds, "employee")              dim dTable as DataTable = ds.Tables("employee")       Dim CurrRows() as DataRow = dTable.Select(Nothing,Nothing, DataViewRowState.CurrentRows)       Dim I, J as integer       Dim strOutput as string       For I = 0 to CurrRows.Length - 1          For J = 0 to dTable.Columns.Count - 1             strOutput = strOutput & dTable.Columns(J). _                ColumnName & " = " & CurrRows(I)(J).ToString & _                "<br>"          next       next       Response.write(strOutput)    end sub    </script> <html><body> </body></html>