可以请有人解释这段代码吗?

时间:2016-04-23 19:51:44

标签: vb.net visual-studio-2010

我在VB 2010中建立了一个连接字符串,并且很容易理解,但我无法弄清楚里面发生了什么。

 private: System::Void button1_Click(System::Object^  sender,System::EventArgs^  e) {

MySqlConnection^ con =gcnew MySqlConnection("server=localhost;port=3306;userid=root;password=themohal123;database=myfirstdb");
        try
         {
             con->Open();
             MessageBox::Show("Connection Successful");
             con->Close();


        }
        catch (Exception^ ex)
        {
         MessageBox::Show("Connection Not Successful"+ ex);
        }


         }

1 个答案:

答案 0 :(得分:0)

它不是vb,它检查mysql连接状态。如果你想启动vb.net,你可以使用这个好东西。你给它返回数据表结果的字符串查询

Public Function mysql(ByVal str_query As String) As DataTable
  Dim adptr As New MySqlDataAdapter
    Dim filltab As New DataTable
    Try
        Using cnn As New MySqlConnection("server=" & mysql_server & ";user=" & mysql_user & ";password=" & mysql_password & ";database=" & mysql_database & ";Allow User Variables=True")
            Using cmd As New MySqlCommand(str_query, cnn)
                cnn.Open()
                               adptr = New MySqlDataAdapter(cmd)
                adptr.Fill(filltab)
                cnn.Close()
            End Using
        End Using
    Catch ex As Exception

'你可以将mysql错误记录到这里的文件log(ex.ToString)         结束尝试         返回filltab     结束功能