Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

connection

Status
Not open for further replies.

adamdavies

Programmer
May 21, 2003
20
AU
im using windows xp.

ive set up a new virtual directory through computer manager, service and applications, internet info service, web sites, new virtual directory.
Alias - BegASPNETdb
Directory - c:\BegASPNETdb\webroot

From an example in asp.net book, i created another folder called ch03. In here ive created a .aspx file

<%@ Import namespace=&quot;System.Data&quot; %>
<%@ Import namespace=&quot;System.Data.OleDb&quot; %>

<html>
<head>
<title>Access DB</title>
</head>

<body>
<h3>Access DB</h3>
<asp:dataGrid id=&quot;dgSuppliers&quot; runat=&quot;server&quot;/>
<body>
</html>

<script language=&quot;VB&quot; runat=&quot;server&quot;>
Sub Page_Load(Source As Object, E As EventArgs)
Dim strConnection As String = &quot;Provider=Microsoft.Jet.OleDb.4.0;&quot;& _
&quot;data source=C:\BegASPNETdb\datastores\nwind.mdb;&quot;

Dim objConnection As New OleDbConnection(strConnection)
Dim strSQL As String = &quot;SELECT * FROM Suppliers;&quot;
Dim objCommand As New OleDbCommand(strSQL, objConnection)

objConnection.Open()
dgSuppliers.DataSource = objCommand.ExecuteReader()
dgSuppliers.DataBind()
objConnection.Close()
End Sub
</script>

i placed the nwind.mdb database in another folder called datastores.

I run all i get up is the heading Access DB.

Does anybody know where i am going wrong and why i cant view the contents of the table suppliers in the nwind db.

I also tried with msde and set up the services, this also did not work for me.

thanks
adam
 
I think it is the fact that you are using a datareader..

As this is a readonly forward only recordset, you won't get much.

Try using a dataadapter and a datatable..

Something like



Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim cn As New OleDb.OleDbConnection(&quot;Provider=Microsoft.Jet.OleDb.4.0;&quot; & _
&quot;data source=C:\db1.mdb&quot;)
cn.Open()
Dim dt As New DataTable
Dim da As New OleDb.OleDbDataAdapter(&quot;Select * from authors&quot;, cn)
da.Fill(dt)
da.Dispose()
DGrid1.DataSource = dt
DGrid1.DataBind()
dt.Dispose()
cn.Close()
cn.Dispose()

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top