vb.net 未定义类型“MySqlConnection”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29094224/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Type 'MySqlConnection' is not defined
提问by Ashley Hooithin
I am facing the error on the below code while i created a function call class at app_code.
我在 app_code 上创建了一个函数调用类时,遇到了以下代码的错误。
My error is showing -->BC30002: Type 'MySqlConnection' is not defined. Please help.Thanks!
我的错误显示 --> BC30002:未定义类型“MySqlConnection”。请帮忙。谢谢!
Imports System.Data
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports MySql.Data.MySqlClient
Namespace check90daysreturn
Public Class Check90days
Public Function check(ByVal datereceived As String, ByVal shipdate As String, ByVal partsn As String)
Dim con As String = ConfigurationManager.ConnectionStrings("xxxConnectionString").ConnectionString
Dim Sql As New MySqlConnection(con)
Dim reader2 As Object
Dim theQuery2 As String = "SELECT Max(shipmentdate) FROM prc.tbsrparts t WHERE Substring(partsn, 17, 11) = '" + partsn.ToString + "'" 'get latest shipment date from database
Dim command2 As New MySqlCommand(theQuery2, Sql)
reader2 = command2.ExecuteScalar
'send auto email
Dim mailmssg As New MailMessage()
Dim smtp_client As New SmtpClient
mailmssg.IsBodyHtml = True
smtp_client = New SmtpClient
smtp_client.Host = "ll.smtp.xxxxx.com"
smtp_client.Port = 25
mailmssg.From = New MailAddress("[email protected]")
mailmssg.CC.Add("[email protected]")
mailmssg.Subject = "(Testing)"
mailmssg.Body = "Testing"
smtp_client.DeliveryMethod = SmtpDeliveryMethod.Network
smtp_client.Send(mailmssg)
End Function
End Class
End Namespace
回答by Viral
I got the same error.
我得到了同样的错误。
After adding
添加后
Imports MySql.Data.MySqlClient;
, and a reference to the MySql.Data.dllI got 'MySqlConnection is not defined'.
,以及对MySql.Data.dll我得到的“未定义 MySqlConnection”的引用。
I have fixed it by adding the reference MySql.Data.dllfrom the older version that is V2.0instead of V4.5.
我通过添加MySql.Data.dll旧版本的引用V2.0而不是V4.5.
回答by Otema
Sometimes adding the refernce to MySql.Data.dll becomes problematic if it is not listed in the reference tab of your project's prpoerties. In this case if you are sure that you have installed the MySql connector then simply choose add reference, on the dialog box shown choose browse then navigate to the folder inwhich it is installed in my case it is C:\Program Files (x86)\MySQL\Connector NET 6.10\Assemblies\v4.5.2 then select MySql.Data.dll click on open then add and it should work alright
有时,如果 MySql.Data.dll 的引用未列在项目属性的引用选项卡中,则会出现问题。在这种情况下,如果您确定已经安装了 MySql 连接器,那么只需选择添加引用,在显示的对话框中选择浏览,然后导航到安装它的文件夹,在我的情况下是 C:\Program Files (x86)\ MySQL\Connector NET 6.10\Assemblies\v4.5.2 然后选择 MySql.Data.dll 单击打开然后添加它应该可以正常工作
回答by hcoder
In my scenario,the problem was fairly simple. The project I worked on was targeting framework version 4.5 of .Net where as MySql.Data was targeted towards .Net 4.5.2 version. MySql.Data version should be lower or equal to the project target framework version. So I changed the project target version to 4.5.2 and it compiled successfully. Hope that helps someone.
在我的场景中,问题相当简单。我参与的项目针对 .Net 的框架版本 4.5,而 MySql.Data 则针对 .Net 4.5.2 版本。MySql.Data 版本应低于或等于项目目标框架版本。于是我把项目目标版本改成了4.5.2,编译成功。希望能帮助某人。
回答by Tim Schmelter
So you have already added Imports MySql.Data.MySqlClient. But have you also added a reference to the MySql.Data.dll?
所以你已经添加了Imports MySql.Data.MySqlClient. 但是您是否还添加了对MySql.Data.dll?

