Hi guys,

I've been using asp.net 2.0 over the past 2 years making simple web applications but have never used it with MySQL.

I've been asked to create a website for a relative. The site will be a vehicle leasing company. After speaking to owner and understanding his requirements i will be able to create the majority of it with no problem. However, as its a leasing company vehicles will need to be added/deleted on a regular basis so i assume having a database (MySQL) connected to the site will be the easiest way to achieve this. Furthermore, it would make sense to have an image of the vehicle too, will MySQL be able to retrieve the images?

I have Visual Studio 2005 installed as well as MySQl 5.1, MySQL Connector/ODBC 5.1 and the MySQL Connector Net 6.0.3.

I have created a new project and placed the following code in my source file:

<%@ Page Language="VB" Debug="true" AutoEventWireup="false" CodeFile="DBConnection.aspx.vb" Inherits="DBConnection" %>

<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "MySql.Data.MySqlClient" %>

<script language="VB" runat="server">

    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        Dim myConnection As MySqlConnection
        Dim myDataAdapter As MySqlDataAdapter
        Dim myDataSet As DataSet

        Dim strSQL As String
        'Dim iRecordCount As Integer

        myConnection = New MySqlConnection("server=localhost; user id=15secs; password=password; database=mydatabase; pooling=false;")

        strSQL = "SELECT * FROM mytable;"

        myDataAdapter = New MySqlDataAdapter(strSQL, myConnection)
        myDataSet = New DataSet()
        myDataAdapter.Fill(myDataSet, "mytable")

        MySQLDataGrid.DataSource = myDataSet
        MySQLDataGrid.DataBind()

    End Sub
   
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>S Q L Connection</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <asp:DataGrid id="MySQLDataGrid" runat="server" />
    
    </div>
    </form>
</body>
</html>

Originally a number of errors were produced however after some bug fixing these were eliminated by placing the 'MySql.Data.dll' within the AppData folder as well as adding a reference to this file via the Windows tab - Add Refrence..

After compling the file zero errors/warning are shown, however, when i open the file within the web the contents of the database does not appear. I have double checked that there is data in the db declared.

Apologies for the long message, but i thought the more info the better..

Please can anyone see what i've done wrong??

Thanks.

Dani AI

Generated

Quick, practical checklist and fixes based on what described — these are the things that most often make a DataGrid come up empty even when a query and assemblies appear correct.

The single biggest gotcha here is that your page’s Load handler might not be running. With AutoEventWireup="false" the Page_Load method must be explicitly hooked to the Load event. Either set AutoEventWireup="true" in the page directive or change the method signature so the event is handled, for example:

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    ' data-loading code here
End Sub

Assembly placement and runtime visibility: assemblies for an ASP.NET app belong in the site’s bin folder (or installed into the GAC). Dropping MySql.Data.dll into App_Data will not make it available to the runtime the same way. Also confirm the Connector/NET version targets the same .NET runtime as your site.

Troubleshooting steps to confirm what’s failing: enable full error output (temporarily), wrap the DB calls in a try/catch and log any exception, and inspect the DataSet.Tables[0].Rows.Count after Fill to verify rows were returned. Verify the MySQL service is running, that the DB user has privileges from localhost, and that your connection string includes any nonstandard port if used.

Images and architecture: for a vehicle catalog it’s usually best to store images on disk (or cloud storage) and save the relative path in the DB — simpler to serve, cache, and back up. If you must store images in MySQL use BLOB (MEDIUMBLOB/LONGBLOB as needed) and serve them through a streaming handler (IHttpHandler/ashx) that writes the correct Content-Type. Finally, prefer MySQL over Access for a web-hosted, multi-user site — Access can work for a tiny internal site but is not recommended for production web apps.

Or would it be better to use a Microsoft Access db for this type of application? Maybe be this would be a lot simpler than using MySQL??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.