没有为类型“ADODB.Connection”和“ADODB.ConnectionClass”定义运算符
刚学VB 2008 制作一个简单的数据操作列子
代码如下:
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Dim cnStr As String = "Persist Security Info=False;User ID=sa;password=eisoft;Initial Catalog=LF_DB;Data Source=ERPSERVER"
Dim cn As New SqlConnection(cnStr)
cn.Open()
Dim sql As String = "select * from printdata"
Dim da As New SqlDataAdapter(sql, cn)
Dim ds As New DataSet
da.Fill(ds, "printdata")
DataGridView1.DataSource = ds.Tables("printdata").DefaultView
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
End Sub
End Class
运行出现错误:
错误1不再支持“Let”和“Set”赋值语句。G:\vb2008\复件 test\test\Module1.vb错 误2没有为类型“ADODB.Connection”和“ADODB.ConnectionClass”定义运算符“=”。错误3应为“=”。
Microsoft ActiveX Data Objects2.x Library 也引用了 谢谢
[解决办法]
Dim cn As New SqlConnection(cnStr)
Dim sql As String = "select * from printdata"
Dim sqlcmd As New SqlCommand(sql, cn) '定义sqlCommand
Dim da As New SqlDataAdapter(sqlcmd)
cn.Open()
Dim ds As New DataSet
da.Fill(ds, "printdata")
DataGridView1.DataSource = ds.Tables("printdata").DefaultView