|
-
Feb 1st, 2004, 01:22 AM
#1
Thread Starter
New Member
unable to connect to MS Access database with ASP.NET code. PLEASE PLEASE HELP??
Hi
I am new to ASP.NET. I have spent a whole day tried to figure out why the below asp.net code CAN'T open/display the content of the database "Northwind.mdb", which is MS Access database.
Could someone please help me why the below code doesn't work? Thank you so much
I found the below code at this website: http://www.w3schools.com/aspnet/aspnet_dbconnection.asp
----- my_access.aspx --------------------------
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
sub Page_Load
dim dbconn,sql,dbcomm,dbread
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
data source=" & server.mappath("northwind.mdb"))
dbconn.Open()
sql="SELECT * FROM customers"
dbcomm=New OleDbCommand(sql,dbconn)
dbread=dbcomm.ExecuteReader()
customers.DataSource=dbread
customers.DataBind()
dbread.Close()
dbconn.Close()
end sub
</script>
<html>
<body><form runat="server">
<asp:Repeater id="customers" runat="server"><HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>Companyname</th>
<th>Contactname</th>
<th>Address</th>
<th>City</th>
</tr>
</HeaderTemplate><ItemTemplate>
<tr>
<td><%#Container.DataItem("companyname")%></td>
<td><%#Container.DataItem("contactname")%></td>
<td><%#Container.DataItem("address")%></td>
<td><%#Container.DataItem("city")%></td>
</tr>
</ItemTemplate><FooterTemplate>
</table>
</FooterTemplate></asp:Repeater>
</form></body>
</html>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|