Results 1 to 4 of 4

Thread: Datagrid view with Vb.net and mysql

  1. #1
    Fried Chip Extremist alsenior's Avatar
    Join Date
    Nov 2005
    Location
    Stafford
    Posts
    2,949
    Thanks
    103
    Thanked
    191 times in 145 posts
    • alsenior's system
      • Motherboard:
      • DFI Lanparty Jr x58-T3H6
      • CPU:
      • Core i7 920
      • Memory:
      • 6 x 2GB ocz Gold
      • Storage:
      • 1 TB Samsung F3
      • Graphics card(s):
      • 1gb 4890 vapor-x xfire
      • PSU:
      • xfx 850W
      • Case:
      • Lian-li Pc7
      • Operating System:
      • Windows 7 X64
      • Monitor(s):
      • Dell 2208WFP
      • Internet:
      • 30mb Virgin media

    Datagrid view with Vb.net and mysql

    Basically im trying to fill a Datagrid with the data from a mysql query

    Basically i need to get the Data from the mysql Data adapter into the data grid veiw. The datagrid Veiw is called dgridmain. basically the code below returns

    Error: Fill: Select.command has not been initialised.

    Any help Please

    Code:
            
            Dim searchtype As String
            Dim searchitem As String
            Dim precordcountint32 As String
    
            searchtype = "description"
    
            If RadioButton1.Checked = True Then
                searchtype = "barcode"
            ElseIf RadioButton2.Checked = True Then
                searchtype = "sku"
            ElseIf RadioButton3.Checked = True Then
                searchtype = "description"
            End If
    
            searchitem = TextBox1.Text
    
            Dim searchquerycmd As New MySql.Data.MySqlClient.MySqlCommand("SELECT * from products where " & searchtype & " = " & searchitem & "")
    
            Try
                Dim myConnectionString As String
                myConnectionString = "Database=ames;Data Source=" & globalserver & ";User Id=amesuser;Password=amespassword;"
                Dim myConnection As New MySql.Data.MySqlClient.MySqlConnection(myConnectionString)
                myConnection.Open()
    
                Using mMySqlDataAdapter As New MySql.Data.MySqlClient.MySqlDataAdapter(searchquerycmd)
                    Using mDataSet As New DataSet
                        mDataSet.Clear()
                        mMySqlDataAdapter.Fill(mDataSet, "data")
                        mDataView = New DataView
                        mDataView.Table = mDataSet.Tables("data")
                        precordcountint32 = mDataView.Count
                    End Using
                End Using
                myConnection.Close()
            Catch searcherror As MySql.Data.MySqlClient.MySqlException
                MessageBox.Show("Error With Search " & searcherror.Message)
            Catch ex As Exception
                MessageBox.Show("Error : " & ex.Message)
            End Try
    Quote Originally Posted by Jay View Post
    What kind of emergency would need Windows 95? I think you are already in a bad state of emergency when your backup plan is Windows 95.
    Beginners guide to raid Beginners guide to raid post edition Hexus.Social - FAQ

  2. #2
    Fried Chip Extremist alsenior's Avatar
    Join Date
    Nov 2005
    Location
    Stafford
    Posts
    2,949
    Thanks
    103
    Thanked
    191 times in 145 posts
    • alsenior's system
      • Motherboard:
      • DFI Lanparty Jr x58-T3H6
      • CPU:
      • Core i7 920
      • Memory:
      • 6 x 2GB ocz Gold
      • Storage:
      • 1 TB Samsung F3
      • Graphics card(s):
      • 1gb 4890 vapor-x xfire
      • PSU:
      • xfx 850W
      • Case:
      • Lian-li Pc7
      • Operating System:
      • Windows 7 X64
      • Monitor(s):
      • Dell 2208WFP
      • Internet:
      • 30mb Virgin media

    Re: Datagrid view with Vb.net and mysql

    Bump because i Really need help with this
    Quote Originally Posted by Jay View Post
    What kind of emergency would need Windows 95? I think you are already in a bad state of emergency when your backup plan is Windows 95.
    Beginners guide to raid Beginners guide to raid post edition Hexus.Social - FAQ

  3. #3
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,164
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Re: Datagrid view with Vb.net and mysql

    I don't know what the constructor for the MySqlDataAdapter takes (why, why why why why why why why why on earth are you writing code thats specific to a database, and the 'short bus' of databases at that!)

    but have you tried going

    mMySqlDataAdapter.SelectCommand = searchquerycmd

    Also i hope you check ur inputs!

    throw new ArgumentException (String, String, Exception)

  4. #4
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: Datagrid view with Vb.net and mysql

    I assume the type MySqlConnection is of IDbConnection? MySql must have implemented command parameter-based queries? You should use those.
    To err is human. To really foul things up ... you need a computer.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help connecting to a remote MySQL server...
    By chicken in forum Software
    Replies: 10
    Last Post: 27-11-2007, 11:52 AM
  2. MySQL extension for PHP 5.2.3 not working
    By Jerrythafast in forum Help! Quick Relief From Tech Headaches
    Replies: 18
    Last Post: 13-06-2007, 08:03 PM
  3. Making PHP and MySQL Talk?
    By Dav0s in forum Software
    Replies: 4
    Last Post: 18-09-2005, 10:53 PM
  4. mySQL problems
    By Vini in forum Software
    Replies: 2
    Last Post: 22-08-2005, 01:01 PM

Posting Permissions

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