Connecting ASP.Net to MySQL and storing images.

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 34
Reputation: Lewis_UnderGrad is an unknown quantity at this point 
Solved Threads: 0
Lewis_UnderGrad Lewis_UnderGrad is offline Offline
Light Poster

Connecting ASP.Net to MySQL and storing images.

 
0
  #1
May 9th, 2009
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:

  1. <%@ Page Language="VB" Debug="true" AutoEventWireup="false" CodeFile="DBConnection.aspx.vb" Inherits="DBConnection" %>
  2.  
  3. <%@ Import Namespace = "System.Data" %>
  4. <%@ Import Namespace = "MySql.Data.MySqlClient" %>
  5.  
  6. <script language="VB" runat="server">
  7.  
  8. Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
  9.  
  10. Dim myConnection As MySqlConnection
  11. Dim myDataAdapter As MySqlDataAdapter
  12. Dim myDataSet As DataSet
  13.  
  14. Dim strSQL As String
  15. 'Dim iRecordCount As Integer
  16.  
  17. myConnection = New MySqlConnection("server=localhost; user id=15secs; password=password; database=mydatabase; pooling=false;")
  18.  
  19. strSQL = "SELECT * FROM mytable;"
  20.  
  21. myDataAdapter = New MySqlDataAdapter(strSQL, myConnection)
  22. myDataSet = New DataSet()
  23. myDataAdapter.Fill(myDataSet, "mytable")
  24.  
  25. MySQLDataGrid.DataSource = myDataSet
  26. MySQLDataGrid.DataBind()
  27.  
  28. End Sub
  29.  
  30. </script>
  31.  
  32. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  33.  
  34. <html xmlns="http://www.w3.org/1999/xhtml" >
  35. <head runat="server">
  36. <title>S Q L Connection</title>
  37. </head>
  38. <body>
  39. <form id="form1" runat="server">
  40. <div>
  41.  
  42. <asp:DataGrid id="MySQLDataGrid" runat="server" />
  43.  
  44. </div>
  45. </form>
  46. </body>
  47. </html>
  48.  

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.
Last edited by peter_budo; May 10th, 2009 at 9:33 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 34
Reputation: Lewis_UnderGrad is an unknown quantity at this point 
Solved Threads: 0
Lewis_UnderGrad Lewis_UnderGrad is offline Offline
Light Poster

Re: Connecting ASP.Net to MySQL and storing images.

 
0
  #2
May 10th, 2009
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??
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC