Jump to content

MySQL Database Connection


Recommended Posts

I'm trying to use data from a MySQL database in ASP.NET but it just isn't working! I'm hoping someone can spot an error or two in the code below as to why i keep getting error pages :) I've spent ages scouring the internet for solutions but it just isn't working &/or making any sense whatsoever!The page loads upto the point i either try to open the database (DatabaseConn.Open()) or set the reader up, then it comes up with an error page stating "Server Error in '/' Application. Runtime Error" (Which doesn't make any sense to me, cos i'm still a little bit of a n00b).I have replaced the username, password & data source fields with temp names!Any feedback is much appreciated.

<%@ Import Namespace="System.Data.OleDb" %><script runat="server">Sub Page_Loaddim sqldim DatabaseConndim DatabaseCommdim DataRDatabaseConn = New OleDbConnection("Provider=MySQLProv;Data Source=DSOURCE;User Id=USERNAME;Password=PASSWORD")sql = "SELECT * FROM DataB"DatabaseConn.Open()DatabaseComm = New OleDbCommand( sql, DatabaseConn )DataR = DatabaseComm.ExecuteReader()Catalog.DataSource = DataRCatalog.DataBind()DataR.Close()DatabaseConn.Close()End Sub</script><html><body><form runat="server"><asp:Repeater id="Catalog" runat="server"><HeaderTemplate><table border="1" width="98%></HeaderTemplate><ItemTemplate><tr><td><%#Container.DataItem("FIELD1")%></td><td><%#Container.DataItem("FIELD2")%></td><td><%#Container.DataItem("FIELD3")%></td></tr></ItemTemplate><FooterTemplate></table></FooterTemplate></asp:Repeater></form></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...