MySQL Connection and DataGridView in VB.NET menu

Shout-Out

User Tag List

Results 1 to 5 of 5
  1. #1
    EmiloZ's Avatar Flying Piggy Back
    CoreCoins Purchaser
    Reputation
    538
    Join Date
    Jun 2007
    Posts
    1,393
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Connection and DataGridView in VB.NET

    Requirements:

    MySql Connector/Net
    Download: Here



    First of before starting VB.NET you should have downloaded and installed MySql Connector.

    Now in your project, add the connector to your refrence:




    And scroll down till you find "MySql.Data" then press Add




    Now you have added the refrence..


    Now go into your code, and add the following:

    Code:
    Imports MySql.Data.MySqlClient
    And under Public Class Form1 add:

    Code:
    Dim conn As Common.DbConnection
     Dim da As Common.DbDataAdapter
     Dim ds As DataSet = New DataSet
     Dim cnString As String
     Dim sqlQRY As String
    It should now look like this:




    Now to your design:

    You should make it look like this on the form:



    It is simpley just the following:

    5x TextBox

    2x Button

    5 x Labels

    1 x GroupBox

    and 1 x DataGridView


    Everyone of them are default in VB.NET


    Now when you have inserted it in your way, then you should double click the button where it says "Get Data", for editing your code for Button1_Click



    At this point, you should insert the following under Button1_Click:

    Code:
            cnString = "datasource=" + TextBox1.Text + ";username=" + TextBox4.Text + ";password=" + TextBox5.Text + ";database=" + TextBox2.Text + ""
    
            sqlQRY = "Select * from " + TextBox3.Text + ""
    
            conn = New MySqlConnection(cnString)
    
            Try
    
                conn.Open()
    
                da = New MySqlDataAdapter(sqlQRY, conn)
    
    
                Dim cb As MySqlCommandBuilder = New MySqlCommandBuilder(da)
    
    
                da.Fill(ds, "" + TextBox3.Text + "")
    
                DataGridView1.DataSource = ds
                DataGridView1.DataMember = "" + TextBox3.Text + ""
    
            Catch ex As Common.DbException
                MsgBox(ex.ToString)
            Finally
    
                conn.Close()
            End Try
    And it will look like this:



    Now you have the connection and fetching done, and when you open you application it will now load every data in the table of yours.


    Now you will have to make the button that says "Save Data" work, so when you press it, it will save the data you edited in the fields:


    As before, double click the button and it will go to its code.

    Insert the following:

    Code:
            da.Update(ds, "" + TextBox3.Text + "")
            MsgBox("Data sent", MsgBoxStyle.OkOnly, "Sucess")

    It will look like this:





    And now you just made a application fetching data from your SQL database, and you are also able to edit it!





    Hope it helped you out!


    If you have any problems with it, I attached my source down below!

    [ATTACH]3767[/ATTACH


    Cheerio!
    Attached Files Attached Files
    Why fill up a signature?

    MySQL Connection and DataGridView in VB.NET
  2. Thanks NovaYear (1 members gave Thanks to EmiloZ for this useful post)
  3. #2
    Dombo's Avatar Banned
    Reputation
    622
    Join Date
    Nov 2008
    Posts
    1,421
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks nice, but I prefer the ADO.NET connector, which allows you to use any db, mySQL, Oracle, MSSQL, etc. No big deal but ideal for larger projects and projects that require high flexability.

  4. #3
    DarkLinux's Avatar Former Staff
    CoreCoins Purchaser Authenticator enabled
    Reputation
    1627
    Join Date
    May 2010
    Posts
    1,846
    Thanks G/R
    193/539
    Trade Feedback
    16 (100%)
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Looks good! Would love to see a ADO.NET method also. Would save me a little time in the future.

  5. #4
    muslim's Avatar Private
    Reputation
    1
    Join Date
    Feb 2012
    Posts
    1
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thx emiloz !! I could not download !! this project !!

  6. #5
    jhonedwardvasquez's Avatar Private
    Reputation
    1
    Join Date
    Apr 2013
    Posts
    1
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    esta vació el contenido, no carga nada

Similar Threads

  1. Ascent, PHP, MySQL, Apache and how they work together
    By scottyrabbit in forum WoW EMU Guides & Tutorials
    Replies: 9
    Last Post: 04-22-2008, 05:07 PM
  2. Ascent, PHP, MySQL, Apache and how they work together
    By scottyrabbit in forum WoW EMU Guides & Tutorials
    Replies: 2
    Last Post: 04-13-2008, 06:49 AM
  3. Problem With MySQL Connection
    By omarer in forum World of Warcraft Emulator Servers
    Replies: 3
    Last Post: 12-07-2007, 01:02 AM
  4. Connections and WoW
    By Gothian in forum World of Warcraft Emulator Servers
    Replies: 10
    Last Post: 11-16-2007, 11:31 AM
  5. Connections and WoW
    By Gothian in forum Community Chat
    Replies: 6
    Last Post: 10-29-2007, 08:02 AM
All times are GMT -5. The time now is 02:16 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search