连接Mysql会出现错误,但我也能以其他形式进行 [英] Connecting Mysql Getting Error But I Can Do It In Other Form Also
问题描述
我真的很困惑。我可以在一个Windows应用程序表单中成功连接mysql。但是我在其他窗口中无法做同样的代码!!!!
I am really getting confused. I could connect mysql successfully in one windows application form. But same code I cannot do in other windows form!!!!
Imports MySql.Data
Imports MySql.Data.MySqlClient
Public Class mysqltblinsert
Dim cont As Mysqlconnnection
Try
cont = New MySqlConnection
cont.ConnectionString = "server=localhost;user id=root;password=xxx;database=mydatabase1;"
cont.Open()
Dim str As String = "select * from mydatabase1.tblemp; "
Dim da As New MySqlDataAdapter("select * from tblemp;", cont)
Dim ds As New DataSet
da.Fill(ds, "tblemp")
cont.Close()
DGV.DataSource = ds.Tables("tblemp")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Error 1 Value of type 'MySql.Data.MySqlClient.MySqlConnection' cannot be converted to 'codeprojects.Mysqlconnnection'.
Error 2 'ConnectionString' is not a member of 'codeprojects.Mysqlconnnection'.
Error 3 'Open' is not a member of 'codeprojects.Mysqlconnnection'
Error 4 Overload resolution failed because no accessible 'New' can be called with these arguments:
'Public Sub New(selectCommandText As String, selectConnString As String)':
推荐答案
问题在于
Dim cont As Mysqlconnnection
Clue在第一条错误消息中
Clue is in the first error message
类型'MySql.Data.MySqlClient.MySqlConnection'的值无法转换为'codeprojects.Mysqlconnnection'
Value of type 'MySql.Data.MySqlClient.MySqlConnection' cannot be converted to 'codeprojects.Mysqlconnnection'
注意字母的大小写。使用
Note the case of the letters. Use
Dim cont As MySqlConnection
所有其他错误(如所列出的)将随之消失。注意 - 通常是这种情况,总是尝试修复报告的第一个问题,然后查看错误列表。
All of the other errors (as listed) will then go away. Note - this is often the case, always attempt to fix the first problem reported and then review the error list.
这篇关于连接Mysql会出现错误,但我也能以其他形式进行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!