开发者

Connecting to a Online MySQL Database using VB.Net

开发者 https://www.devze.com 2022-12-20 11:28 出处:网络
I\'ve searc开发者_高级运维hed around and haven\'t been able to find anything along the lines of doing this.You need to install Connector/Net, which will give you a full ADO.Net provider for MySql you

I've searc开发者_高级运维hed around and haven't been able to find anything along the lines of doing this.


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.


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


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()


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消