Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Database and Reporting > Can't find mysql on the add reference section


Reply
 
Thread Tools Display Modes
  #1  
Old 06-29-2012, 02:29 AM
Ktech22 Ktech22 is offline
Newcomer
 
Join Date: Jun 2012
Posts: 20
Default Can't find mysql on the add reference section


hi
I am creating a database project where I take my data from mysql database and then create graphs and charts.
I currently have microsoft visual basic 2010 express edition. I am familiar with visual basic but have never used mysql before. I have quried a database into mysql and server connection to the database is working fine. Furthermore I downloaded mysql a week ago so I have the latest connector.
I looked at many youtube tutorials and have tried to find mysql.data in the add reference section (in project) but it doesn't seem to be
there.
I know this might be a stupid question compared to the other threads but please could you help.
Thanks in advance
Ktech22
Reply With Quote
  #2  
Old 06-30-2012, 06:07 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default MySQL to .Net the basic code

Quote:
Originally Posted by Ktech22
I am familiar with visual basic but have never used MySQL before.
This is not surprising.
MySQL tends to be used on Linux (Apache / Tomcat) servers more than Windows servers
and most Linux MySQL setups use php (not VB.Net) to access and query the MySQL database.
Quote:
Originally Posted by Ktech22
I have queried a database into MySQL and server connection to the database is working fine.
Furthermore I downloaded MySQL a week ago so I have the latest connector.
Establishing the connection is half the battle, but it would have been nice for you to have shown what code you were using,
just so we have a starting point for figuring out how the code needs to be modified
to complete the rest of what you want to do..

Failing that all I can do is give you the basic code for dealing with MySQL under .Net
(once you have the .Net MySQL connector downloaded and properly referenced):
Code:
Imports MySql.Data.MySqlClient
Public Class Form1    
    Private MyConn As MySqlConnection
    Private MyComm As MySqlCommand
    Private MyCmd As New MySqlCommand
    Dim conn As MySqlConnection
    Dim SqlConn As String = "Server=xx.xx.xxx.xxx;Port=3306;Database=some_name;Uid=some_name;Pwd=something;"

  'cmdLogin is a command button control
  Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
    'assign the row number based on a the value
    'of a trackbar slider control
    Dim strRowNum As String = tb1.Value
    Try
            MyConn = New MySqlConnection
            MyConn.ConnectionString = SqlConn
            MyConn.Open()
              'MessageBox.Show("Debug: Connection to Database has been opened.")
            Using MyConn
              Dim command As MySqlCommand = New MySqlCommand("SELECT * FROM tablename WHERE field0 =" & strRowNum & ";", MyConn)
              Dim reader As MySqlDataReader = command.ExecuteReader()
              If reader.HasRows Then
                Do While reader.Read
                  'txt1 is a Textbox control with multiline property set to True
                  txt1.Text = txt1.Text & reader.GetInt32(0) & ", " & reader.GetString(1) _
                   & ", " & reader.GetString(2) & ", " & reader.GetString(3) _
                   & ", " & reader.GetString(4) & ", " & reader.GetString(5) _
                   & ", " & reader.GetString(6) & ", " & reader.GetString(7) & vbCrLf
                Loop
              End If
            End Using
            MyConn.Close()
        Catch myerror As MySqlException
            MessageBox.Show("Cannot connect to database: " & myerror.Message)
            Exit Sub
        Finally
            MyConn.Dispose()
        End Try
  End Sub
End Class
Some additional notes:
1.) The SQL connection string formatting is critical. Here is a good reference
2.) Of course "reader.GetInt32" is used for numerical data (like primary key auto-increment fields),
but "reader.GetInt16" may be substituted in small databases.
3.) Also, of course, "reader.GetString" is used for non-numeric data,
but I use it for UPC numbers as well ("field7") since the database was exported from a Linux
proprietary program and for interchange purposes may be "Null"
Please see the GoDaddy Starfield Technologies screenshot attached below
(other phpMyAdmins may be different, though),
and note "field0" through "field7" are considered columns names for MySQL command purposes.
4.) You would think that the Microsoft MSDN will be totally useless for MySQL
since Microsoft has its own SQL Server setup, but if you take a look at
this page you will notice a striking similarity in the way the reader code is structured.
5.) This is the most super-simple "just-get-it-working" code example.
A more real world example would probably use a datagrid,
or use a loop to sequentially load the data into an array for storage before using it,
for instance, to create (custom draw) graphs and charts.
6.) As regard "mysql.data" I really have no idea what you are talking about
because you failed to adequately cite/reference the YouTube videos you mentioned in passing,
but once the MySQL connection is established all data acquisition (queries)
can be done through feeding the right SQL commands for what you want.

edit: Maybe you having trouble referencing the dll from within the VB.Net IDE.
In which case these links might be helpful (1, 2, 3)

Last edited by surfR2911; 06-30-2012 at 06:53 PM.
Reply With Quote
  #3  
Old 07-04-2012, 09:05 AM
Ktech22 Ktech22 is offline
Newcomer
 
Join Date: Jun 2012
Posts: 20
Default

Quote:
Establishing the connection is half the battle, but it would have been nice for you to have shown what code you were using,
just so we have a starting point for figuring out how the code needs to be modified
to complete the rest of what you want to do..
Sorry for the late reply I had to hand in coursework and I had to solve any problem. I cant seem to add the reference so I couldn't even start the code. Sorry if this is a stupid question as this is my first time with databases but to I have to dump my data into my documents and then connect my vb to that.

Another thing that I wanted to ask was that I was looking at the mysql manual manual.gif It says that connector 6.3.2 later version don't allow the express version of vb to connect to it. Is this true or can I get around it.
Sorry for any stupid question and thank you in advanced
Ktech22
Reply With Quote
  #4  
Old 07-04-2012, 09:40 AM
Ktech22 Ktech22 is offline
Newcomer
 
Join Date: Jun 2012
Posts: 20
Default

Sorry disregard my last reply I just found
out how to reference it
thanks for the links and the notes it help me to work
out how to reference it
thankyou I will start creating my code
thanks
ktech22
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->