Answered by:
retrieving records from access db

Question
-
User-1890252405 posted
i need to retrieve all the records present in a database
iam using the following code but it fails to show any record
Dim con As New System.Data.OleDb.OleDbConnection
Dim myPath As StringmyPath = Server.MapPath("abc.mdb")con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & myPath & ";"Dim adp As New System.Data.OleDb.OleDbDataAdapter("select * from Stutable", con)Dim dt As New System.Data.DataTableadp.Fill(dt)For i As Integer = 0 To dt.Rows.Count - 1Dim myRow As New HtmlTableRowDim myCell As New HtmlTableCellDim mytable As New HtmlTablemyCell.InnerHtml = dt.Rows(i).Item("studentname") & " " & dt.Rows(i).Item("rollno") & " " & dt.Rows(i).Item("branch") & " " & dt.Rows(i).Item("year of joining") & " " & dt.Rows(i).Item("DOB") & " " & dt.Rows(i).Item("house no") & " " & dt.Rows(i).Item("street") & " " & dt.Rows(i).Item("city") & " " & dt.Rows(i).Item("PIN") & " " & dt.Rows(i).Item("ph no") & " " & dt.Rows(i).Item("Hobbies") & " " & dt.Rows(i).Item("Technical Speciallization")myRow.Cells.Add(myCell)mytable.Rows.Add(myRow)NextEnd SubEnd ClassDim myPath As String
myPath = Server.MapPath("abc.mdb")
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & myPath & ";"
Dim adp As New System.Data.OleDb.OleDbDataAdapter("select * from Stutable", con)
Dim dt As New System.Data.DataTable
adp.Fill(dt)
For i As Integer = 0 To dt.Rows.Count - 1
Dim myRow As New HtmlTableRow
Dim myCell As New HtmlTableCell
Dim mytable As New HtmlTable
myCell.InnerHtml = dt.Rows(i).Item("studentname") & " " & dt.Rows(i).Item("rollno") & " " & dt.Rows(i).Item("branch") & " " & dt.Rows(i).Item("year of joining") & " " & dt.Rows(i).Item("DOB") & " " & dt.Rows(i).Item("house no") & " " & dt.Rows(i).Item("street") & " " & dt.Rows(i).Item("city") & " " & dt.Rows(i).Item("PIN") & " " & dt.Rows(i).Item("ph no") & " " & dt.Rows(i).Item("Hobbies") & " " & dt.Rows(i).Item("Technical Speciallization")
myRow.Cells.Add(myCell)
mytable.Rows.Add(myRow)
Next
End Sub
End Class
Monday, May 31, 2010 1:06 AM
Answers
-
User-821857111 posted
You don't show enough code to confirm whether you are adding the HtmlTable to the Page's controls collection. But this is a slow way to do things. Why not just add a GridView to the form, and then do this:
Dim con As New System.Data.OleDb.OleDbConnection Dim myPath As String myPath = Server.MapPath("abc.mdb") con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & myPath & ";" Dim adp As New System.Data.OleDb.OleDbDataAdapter("select * from Stutable", con) Dim dt As New System.Data.DataTable adp.Fill(dt) GridView1.Datasource = dt GridView1.Databind()
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, May 31, 2010 2:45 AM -
User-1179126167 posted
hi,
where are u opened the connection,
i mean con.Open();
thanks
r.e
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, May 31, 2010 2:48 AM -
User-821857111 posted
i mean con.Open();You don't need to open or close the connection when using Data.Adapter.Fill(). The Fill() method does that for you.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, May 31, 2010 10:04 AM
All replies
-
User-821857111 posted
You don't show enough code to confirm whether you are adding the HtmlTable to the Page's controls collection. But this is a slow way to do things. Why not just add a GridView to the form, and then do this:
Dim con As New System.Data.OleDb.OleDbConnection Dim myPath As String myPath = Server.MapPath("abc.mdb") con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & myPath & ";" Dim adp As New System.Data.OleDb.OleDbDataAdapter("select * from Stutable", con) Dim dt As New System.Data.DataTable adp.Fill(dt) GridView1.Datasource = dt GridView1.Databind()
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, May 31, 2010 2:45 AM -
User-1179126167 posted
hi,
where are u opened the connection,
i mean con.Open();
thanks
r.e
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, May 31, 2010 2:48 AM -
User-821857111 posted
i mean con.Open();You don't need to open or close the connection when using Data.Adapter.Fill(). The Fill() method does that for you.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, May 31, 2010 10:04 AM