j4u Posted December 21, 2007 Share Posted December 21, 2007 Hi I’m new in this forum. Few months ago I used a aspx script from w3schools.com for a guestbook using MSAccess dBase. See original example below. I’m not able to write applications myself. I managed to get this example up and running for few moths ago. Last week it didn’t work anymore. The reason was the host changed the site from asp.net 1.1 into asp.net 2. For me they changed it back again to asp.net 1.1 and now it works again. It will be a matter of time that they will not support asp.net 1.1 anymore. What do I need to change in the code below to get it up and running using asp.net 2? What is used in the coding that is deprecated in asp.net 2? Thx! <%@ Import Namespace="System.Data.OleDb" %><script runat="server">sub Page_Loaddim dbconn,sql,dbcomm,dbreaddbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("/db/northwind.mdb"))dbconn.Open()sql="SELECT * FROM customers"dbcomm=New OleDbCommand(sql,dbconn)dbread=dbcomm.ExecuteReader()customers.DataSource=dbreadcustomers.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 bgcolor="#b0c4de"><th>Companyname</th><th>Contactname</th><th>Address</th><th>City</th></tr></HeaderTemplate><ItemTemplate><tr bgcolor="#f0f0f0"><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> Link to comment Share on other sites More sharing options...
jesh Posted December 21, 2007 Share Posted December 21, 2007 Do you happen to know what errors are being reported?The only thing I see up front about your Repeater and the one's I have in .NET 2.0 are that you have: <td><%#Container.DataItem("companyname")%> </td> Where I have: <td><%# DataBinder.Eval(Container.DataItem, "companyname") %> </td> The only other thing that I would recommend is that you don't bind a DataReader to your Repeater and that you bind a DataTable instead. In C#: DataTable data = new DataTable();data.Load(dbcomm.ExecuteReader());customers.DataSource = data;customers.DataBind(); Otherwise your database connection will remain open until the Repeater has be totally bound. Link to comment Share on other sites More sharing options...
j4u Posted December 22, 2007 Author Share Posted December 22, 2007 Hi Jesh! Thx for the quick reaction. I managed to get the first change up and running. I have some problems with using the DataTable.Complete code: <script runat="server">sub Page_Loaddim dbconn,sql,dbcomm,dbreaddbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data Source=d:\example.mdb;JET OLEDB:Database Password=xxxxxx;")dbconn.Open()sql="SELECT Name, URL, Comment, dDate FROM Guestbook ORDER BY id DESC"dbcomm=New OleDbCommand(sql,dbconn)DataTable data = new DataTable()data.Load(dbcomm.ExecuteReader())customers.DataSource=datacustomers.DataBind()data.Close()dbconn.Close()end sub</script> The error that I get:Compiler Error Message: BC30684: 'DataTable' is a type and cannot be used as an expression.The error refers to the line: DataTable data = new DataTable() If I put <%@ Page Language="C#" Debug="true" %> to the page, I get other messages:Compiler Error Message: CS1002: ; expectedThe error refers to the line: sub Page_Load Do I need top add ";" at the end of all the lines???What do I do wrong?j4u Link to comment Share on other sites More sharing options...
aspnetguy Posted December 23, 2007 Share Posted December 23, 2007 Jesh has provided code that is in C# if you are using VB you will have convert it. Link to comment Share on other sites More sharing options...
j4u Posted December 23, 2007 Author Share Posted December 23, 2007 Hi,The problem is that I didn't write the code myself. I found the code in a tutorial of w3schools. See 1st post... I don't have tools to write VB or C#... I copied and paste the example from w3schools in my own html page and changed some settings... But the example seems only to work in asp.net 1.1. Now I want to know what to change to get it up and running in asp.net 2 because the host will soon stop supporting asp.net 1.1...:-J4U Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.