Tuesday, May 11, 2021

Visual Studio connecting to MySQL

 Video for installing the connector:


Code Project example:


Code Example:

Imports System

Imports System.Data
Imports MySql.Data.MySqlClient
Module Module1
    Sub Main()
        Dim connstring As String = "server=sql5.freemysqlhosting.net;userid=sql5485827;password=kGXeNyGig9;database=sql5485827"
        Dim conn As MySqlConnection = Nothing
        Dim COMMAND As MySqlCommand
        Dim READER As MySqlDataReader
            conn = New MySqlConnection(connstring)
            Console.WriteLine("Connected to the Database")
            Dim Query As String
            Query = "insert into users (id,name) values (2,'Rhonda Rosemary')"
            COMMAND = New MySqlCommand(Query, conn)
            READER = COMMAND.ExecuteReader
            Console.WriteLine("Data Saved")
            Query = "SELECT * FROM users;"
            Dim da As New MySqlDataAdapter(query, conn)
            Dim ds As New DataSet()
            da.Fill(ds, "table_usesr")
            Dim dt As DataTable = ds.Tables("table_name")
            Console.WriteLine("The data in the table is:")
            For Each row As DataRow In dt.Rows
                For Each col As DataColumn In dt.Columns
                    Console.Write(row(col).ToString() + vbTab)
        Catch e As Exception
            Console.WriteLine("Error: {0}", e.ToString())
            If conn IsNot Nothing Then
            End If
        End Try
    End Sub
End Module

No comments:

Post a Comment

Solidworks macros eith ChatGPT

 Record a simple using thr Solidworks macro recorder, upload it to ChatGPT, and explain to ChatGPT how you want it changed:  https://youtu.b...