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.

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??

This article has been dead for over six months. Start a new discussion instead.