Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7705093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:48:32+00:00 2026-05-31T23:48:32+00:00

Im trying to connect MySql from VB.NET in visual basic 2010. I wanted to

  • 0

Im trying to connect MySql from VB.NET in visual basic 2010. I wanted to query the db just to get one return is response to my proID once I click the button. it successfully show connection has been establish but I can’t seems to run any sql query on it. what might have been wrong?

This is the error I got from immediate window:

A first chance exception of type 'System.InvalidOperationException' occurred in MySql.Data.dll

Lets assume num is 1001 from the keypress event.

Public Class Form1
    Private connStr As String = "server=localhost;" & _
                "user id=root;Password=1234561;" & _
                "database = test"
    Dim num As Integer


Private Sub TextBox1_keypress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    Dim str As String
    If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
        str = TextBox1.Text
        Dim splitVals As String() = str.Split(" ")
        num = splitVals(1)
    End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim query As String = "SELECT * FROM products"
    Dim con As New MySqlConnection(connStr)
    Dim cmd As New MySqlCommand(query)
    Try
        con.Open()
        MessageBox.Show("Database Connected")
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()

        con.Close()
    Catch ex As Exception
        Console.WriteLine(ex.Message)
    End Try
End Sub

End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:48:33+00:00Added an answer on May 31, 2026 at 11:48 pm

    ExecuteNonQuery is used for SQL statements that don’t return any data (For example, INSERT, UPDATE, DELETE).

    What do you want to achieve? If you want to fetch all records from product table and display it on a datagrid, then try this:

    Using xConn as New MySqlConnection(connStr)
        Using xComm as new MySQLCommand()
            xComm.Connection = xConn
            xComm.CommandText = "SELECT * FROM products"
            Using xAdapter as new MySQLDAtaAdapter(xComm)
                Dim ds as new Dataset
                xConn.Open()
                xAdapter.Fill(ds)
                datagridview1.datasource = ds.tables(0)
            End Using
        End Using
    End Using
    

    UPDATE 1

    Dim xPrice as Integer = 0
    Using xConn as New MySqlConnection(connStr)
        Using xComm as new MySQLCommand()
            xComm.Connection = xConn
            xComm.CommandText = "SELECT ProductPrice FROM products WHERE proID = @xID"
                xComm.Parameters.AddWithValue("xID", "Value Here")
                xConn.Open()
                xPrice = CInt(xComm.ExecuteScalar())
                xConn.Close
        End Using
    End Using
    
    Msgbox xPrice
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying connect to MySQL database from ASP.net code. some my connection is
I am trying to connect to a remote mysql database from an iPhone. I
I am trying to connect to a remote MySQL database using Visual C# 2008
I'm trying another method to connect mysql and vb.net. I didn't have any difficulties
I'm trying to connect to a MySQL database using my ASP.NET Web Forms Application.
I am trying to connect to mysql database from jsp page. The connection code
I'm trying to connect to a mysql server at dreamhost from a php scrip
I am trying to get Ajaz to pull data from mysql using a php
I am trying to connect to a remote mysql database but I get the
I'm trying to connect to MySQL database from node.js using db-mysql library. Everything works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.