Hi ALL,

Plz tell me how to retrieve data from mysql using vb.net as frontend.
I created database in mysql and able to insert data from vb.net but i dont know how to retrieve data from mysql. Plz help me to perform this action. Plz post your reply for my question....


Regards,
Karthikeyan.

cee_karthi,
Which database product are using MYSQL or MSSQL? Post code if you have. Your source must be surrounded with bb code tags.

[code=vb.net] .. statements..

[/code]

Which database product are using MYSQL or MSSQL? Post code if you have. Your source must be surrounded with bb code tags.
[noparse]
[code=vb.net]
.. statements..
[/code]
[/noparse]

Im using MYSQL. I indicated correctly in the first thread itself.

Edited 3 Years Ago by happygeek: fixed formatting

hi cee_karthi,
if you hv been able to solved your problem..then please mark this thread as solved...

Hi ALL,

Plz tell me how to retrieve data from mysql using vb.net as frontend.
I created database in mysql and able to insert data from vb.net but i dont know how to retrieve data from mysql. Plz help me to perform this action. Plz post your reply for my question....


Regards,
Karthikeyan.

Hey cee_kathi,

Have u solved your problem in retriving data.. By the way i have my code here check it out:

Imports MySql.Data.MySqlClient
Imports System.Data
Public Class Form1
'Write your own Database code in VB .NET Tutorial using MySQL
'The Connection Object
'Dim objConn As MySqlConnection
'Dim objDataAdapter As MySqlDataAdapter
'Dim objDataset As DataSet

Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
Dim objConn As MySqlConnection
Dim objDataset As New DataSet
Dim objDataAdapter As MySqlDataAdapter
Dim sqlConn As String

objConn = New MySqlConnection("server=localhost;userid=root;password=password;database=mydatabase")

objConn.Open()
sqlConn = "select * from movie"
objDataAdapter = New MySqlDataAdapter(sqlConn, objConn)
objDataAdapter.Fill(objDataset, "tblMovie")

MsgBox("The Connection is Now 'OPEN'")

objConn.Close()
MsgBox("The Connection is Now 'CLOSE'")

txtTitle.Text = objDataset.Tables("tblMovie").Rows(1).Item(1)
txtYear.Text = objDataset.Tables("tblMovie").Rows(1).Item(2)

End Sub

this is my references...
http://www.homeandlearn.co.uk/NET/nets12p5.html

hope this one would help you.

By the way can you help me can you give your source code for add data in mysql database.

Thnx..

Carl

Comments
N.A
sqlCom = New SqlCommand("prc_InsertUniversities", sqlCon)
        sqlCom.CommandType = CommandType.StoredProcedure
        sqlCom.Parameters.Add("@Code", SqlDbType.VarChar, 20)
        sqlCom.Parameters.Add("@Name", SqlDbType.VarChar, 20)
        sqlCom.Parameters.Add("@Type", SqlDbType.VarChar, 30)
        sqlCom.Parameters.Add("@Address", SqlDbType.VarChar, 20)
        sqlCom.Parameters.Add("@Email", SqlDbType.VarChar, 20)
        sqlCom.Parameters.Add("@Web", SqlDbType.VarChar, 20)
        sqlCom.Parameters.Add("@Location", SqlDbType.VarChar, 20)
        sqlCom.Parameters.Add("@Period", SqlDbType.VarChar, 20)
        sqlCom.Parameters.Add("@Certification", SqlDbType.VarChar, 20)
        sqlCom.Parameters.Add("@Approved", SqlDbType.VarChar, 20)
        sqlCom.Parameters.Add("@Exparing", SqlDbType.VarChar, 20)

        sqlCom.Parameters("@Code").Value = TextBox1.Text
        sqlCom.Parameters("@Name").Value = TextBox2.Text
        sqlCom.Parameters("@Type").Value = TextBox16.Text
        sqlCom.Parameters("@Address").Value = TextBox3.Text
        sqlCom.Parameters("@Email").Value = TextBox4.Text
        sqlCom.Parameters("@Web").Value = TextBox5.Text
        sqlCom.Parameters("@Location").Value = TextBox6.Text
        sqlCom.Parameters("@Period").Value = TextBox7.Text
        sqlCom.Parameters("@Certification").Value = TextBox13.Text
        sqlCom.Parameters("@Approved").Value = TextBox14.Text
        sqlCom.Parameters("@Exparing").Value = TextBox15.Text

        Try
            sqlCom.ExecuteNonQuery()
            MessageBox.Show("Data Inserted Successfully", "hi", MessageBoxButtons.OK, MessageBoxIcon.Information)
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox16.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
            TextBox5.Text = ""
            TextBox6.Text = ""
            TextBox7.Text = ""
            TextBox13.Text = ""
            TextBox14.Text = ""
            TextBox15.Text = ""
        Catch ex As Exception
            MessageBox.Show("Data Insertion Error", "hi", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

Comments
See the OP, MySQL database connector API will be used.

hello guys,
I have here related problem. Can anybody modify?

here's my code:

Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

    Dim conn As New MySqlConnection
    Dim myCommand As New MySqlCommand
    Dim comm As String
    Dim myconnstring As String
    Dim UserID As Integer
    Dim myReader As MySqlDataReader
    Dim pword As String = PasswordTextBox.Text

    myconnstring = "datasource=localhost;username=root;password=monchito;database=newscoring;"
    conn = New MySqlConnection(myconnstring)
    comm = "SELECT a.`uname`, a.`pword` FROM admin a where `pword` = " + pword

    Try
        conn.Open()

        Try
            myCommand.Connection = conn
            myCommand = New MySqlCommand(comm)

            UserID = myCommand.ExecuteScalar    'my program stop here
            myReader = myCommand.ExecuteReader

            conn.Close()

            While myReader.Read
                TextBox1.Text = myReader.GetValue(myReader.GetOrdinal("pword"))
            End While

            If TextBox1.Text = PasswordTextBox.Text Then
                Dim mainForm As New Form1
                mainForm.UserID = UserID
                mainForm.connectionString = myconnstring
                mainForm.Show()
            End If
        Catch myerror As MySqlException
            MessageBox.Show("Error Connecting to Database: " & myerror.Message)
            conn.Dispose()
            PasswordTextBox.Clear()
        End Try

    Catch myerror As MySqlException
        MessageBox.Show("Error Connecting to Database: " & myerror.Message)
        conn.Dispose()
        PasswordTextBox.Clear()
        PasswordTextBox.Focus()
    End Try
End Sub

Error:
System.InvalidOperationException was unhandled
Message="Connection must be valid and open."
Source="MySql.Data"

Please help...

This article has been dead for over six months. Start a new discussion instead.