Connecting to a Online MySQL Database using VB.Net

前端 未结 5 1201
庸人自扰
庸人自扰 2020-12-20 06:08

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

相关标签:
5条回答
  • 2020-12-20 06:56

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

    0 讨论(0)
  • 2020-12-20 06:58

    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()
    
    0 讨论(0)
  • 2020-12-20 07:00
    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
    
    0 讨论(0)
  • 2020-12-20 07:01

    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.

    0 讨论(0)
  • 2020-12-20 07:01

    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

    0 讨论(0)
提交回复
热议问题