Video for installing the connector:
Code Project example:
https://www.codeproject.com/Articles/43438/Connect-C-to-MySQL
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 Try conn = New MySqlConnection(connstring) conn.Open() 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") READER.Close() Console.ReadLine() 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) Next Console.Write(vbNewLine) Next Catch e As Exception Console.WriteLine("Error: {0}", e.ToString()) Finally If conn IsNot Nothing Then conn.Close() End If End Try Console.ReadLine() End Sub End Module
No comments:
Post a Comment