Results 1 to 5 of 5
  1. #1
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I am just about to embark on this.


    Does anyone know how easy it is to Set up the Data Source ad Data Set for a GridView Control
    using MYSQL as the Source.

    There appears no way to do this through the Visual Set Up Tools, unless it can be done via the MYSQL service but I have NOT figured that one out.
    Alternatively it ought to be possible through code setting the connection string.

    I was using something like

    Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=MyDB;User ID=root;Password=MyPW;")

    With the line

    Imports Mysql.Data.MySqlClient

    But Although I have downloaded the MYSQL Client I must have done the installation incorrectly OR
    maybe not referenced it in the Project correctly because I get a compile error


    Warning 1
    Namespace or type specified in the Imports 'Mysql.Data.MySqlClient' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

    Bit early days for me this one, but having programmed in many languages over the years I am hoping it is something trivial.

    It may be that I need full visual studio rather than express to achieve what I want.

    I have not managed to get it to link to SQL server via the VBE other than Compact Edition which I don't want to use.

    Maybe I need to buy some more books.

    Andrew

  2. #2
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    OK I was being dim.
    I had omitted referencing it in Project Add Reference, once done it worked fine

    Code:
    Imports System.ComponentModel
    Imports System.Drawing
    Imports System.Windows.Forms
    Imports System.Data
    Imports Mysql.Data.MySqlClient
    Imports System
    
    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=tender;User ID=MyUser;Password=MyPW;")
            Dim sql As MySqlCommand = New MySqlCommand("SELECT FirstName,LastName,ContactEMail FROM `Company Contacts`", con)
            Dim ds As DataSet = New DataSet()
            Dim DataAdapter1 As MySqlDataAdapter = New MySqlDataAdapter()
    
            con.Open()
            	DataAdapter1.SelectCommand = sql
            	DataAdapter1.Fill(ds, "tblContacts")
            	DataGridView1.DataSource = ds
            	DataGridView1.DataMember = "tblContacts"
            con.Close()
        End Sub
    End Class


    OK, a bit of work to do now, but at least it works in principle.

    However, is it possible to set up the Data Source via the Visual Tools or can it only be done in code with VB Express

    By the way it works in 2008 and 2010 Beta.
    Andrew

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by AndrewKKWalker View Post
    OK I was being dim.
    I had omitted referencing it in Project Add Reference, once done it worked fine

    Code:
    Imports System.ComponentModel
    Imports System.Drawing
    Imports System.Windows.Forms
    Imports System.Data
    Imports Mysql.Data.MySqlClient
    Imports System
    
    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=tender;User ID=MyUser;Password=MyPW;")
            Dim sql As MySqlCommand = New MySqlCommand("SELECT FirstName,LastName,ContactEMail FROM `Company Contacts`", con)
            Dim ds As DataSet = New DataSet()
            Dim DataAdapter1 As MySqlDataAdapter = New MySqlDataAdapter()
    
            con.Open()
            	DataAdapter1.SelectCommand = sql
            	DataAdapter1.Fill(ds, "tblContacts")
            	DataGridView1.DataSource = ds
            	DataGridView1.DataMember = "tblContacts"
            con.Close()
        End Sub
    End Class


    OK, a bit of work to do now, but at least it works in principle.

    However, is it possible to set up the Data Source via the Visual Tools or can it only be done in code with VB Express

    By the way it works in 2008 and 2010 Beta.

    I never use the visual tools so I can't say. However, you should be able to add a connection to the server explorer and work with that. I don't work with MySQL so I'm not sure what is involved.
    Charlotte

  4. #4
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by charlotte View Post
    I never use the visual tools so I can't say. However, you should be able to add a connection to the server explorer and work with that. I don't work with MySQL so I'm not sure what is involved.

    OK, I'll look into that.
    May have to go onto Amazon and get a couple of books.
    I am using VB Express just to see the implications, but I am coming round to the fact that I will need to get
    Visual Studio for proper development work.
    I am going to need to Web enable anyway so I might as well start as I mean to go on.


    Having just looked, although Server Explorer is available in Visual Studio 2005,
    It does not appear to be available to Visual Basic Express 2008 or 2010 Beta
    Andrew

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by AndrewKKWalker View Post
    OK, I'll look into that.
    May have to go onto Amazon and get a couple of books.
    I am using VB Express just to see the implications, but I am coming round to the fact that I will need to get
    Visual Studio for proper development work.
    I am going to need to Web enable anyway so I might as well start as I mean to go on.


    Having just looked, although Server Explorer is available in Visual Studio 2005,
    It does not appear to be available to Visual Basic Express 2008 or 2010 Beta

    Yes, I forgot that. You still have a DataSource tool, although I don't recall the name at the moment and I don't have express on this machine. If you try adding a datasource to the project, it should become visible.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •