Connecting to a Online MySQL Database using VB.Net

2020-02-13 05:19发布

I've searched around and haven't been able to find anything along the lines of doing this.

5条回答
家丑人穷心不美
2楼-- · 2020-02-13 05:35

I use C#:

const String ConnectionString = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Port=3306;Database=test;User=root;Password=;Option=3;";

OdbcConnection conn = new OdbcConnection(ConnectionString);

conn.Open();

OdbcCommand command = new OdbcCommand();

command.CommandType = CommandType.StoredProcedure;

command.Connection = conn;

command.CommandText = "insert into search (tempsearchKey, state, suburb) values ('" + tempsearchKey+"','"+state+"','"+suburb+"')";

command.ExecuteNonQuery();

command.Cancel();

install odbc driver from mysql website

and convert this to VB.NET,

Maybe this link could help:

http://dev.mysql.com/tech-resources/articles/ebonat-load-and-search-mysql-data-using-vbnet-2005.html

查看更多
孤傲高冷的网名
3楼-- · 2020-02-13 05:49

You need to install Connector/Net, which will give you a full ADO.Net provider for MySql you can use. Be warned that this is GPL software, meaning if you distribute it as part of a commercial product you must also distribute your source code. It's an open legal question, but last I heard most web sites are okay with this, because you are not distributing your server code. Desktop apps may have an issue, though.

查看更多
啃猪蹄的小仙女
4楼-- · 2020-02-13 05:58

Install MySQL connector for .NET, and APACHE, also install XAMPP so you could use phpMyAdmin

查看更多
爱情/是我丢掉的垃圾
5楼-- · 2020-02-13 05:59
Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient
Public Class LoginForm1
    Dim MySQLConnection As MySqlConnection
    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub Cancel_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        End
    End Sub
Private Sub OK_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        MySQLConnection = New MySqlConnection
        MySQLConnection.ConnectionString = "server=db4free.net;Port=3306; User ID=db4freeusername; password=db4freepassword; database=nameofyourdatabase"
        MySQLConnection.Open()

        Dim MyAdapter As New MySqlDataAdapter
        Dim SqlQuary = "SELECT * From nameofthetable WHERE Username='" & UsernameTextBox.Text & "' AND password = '" & PasswordTextBox.Text & "';"
        Dim Command As New MySqlCommand
        Command.Connection = MySQLConnection
        Command.CommandText = SqlQuary
        MyAdapter.SelectCommand = Command
        Dim Mydata As MySqlDataReader
        Mydata = Command.ExecuteReader
        If Mydata.HasRows = 0 Then
            MsgBox("Error During Login:Please Enter Valid Data")
        Else
            Form1.Show()
            Me.Hide()
        End If
    End Sub
End Class
查看更多
狗以群分
6楼-- · 2020-02-13 06:00

First of all you need to install MySQL connector for .NET.

Imports MySql.Data.MySqlClient

Dim myConnection As MySqlConnection = New MySqlConnection()
Dim myConnectionString As String = "Server=SERVERNAME;Database=DATABASE;Uid=root;Pwd=password;"
myConnection.ConnectionString = myConnectionString
myConnection.Open()

//execute queries, etc

myConnection.Close()
查看更多
登录 后发表回答