ERROR[IM002][Microsoft][ODBC驱动程序管理器]未发现数据源名称并且未指定默认驱动程序
还是上次的实践作业:要求用VB2010+ACCESS2007做一个选择省出现对应城市的二级联动
现在代码已经写到这里:
Public Class Form1
Public connectionstring As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
connectionstring = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Application.Info.DirectoryPath & "\MyDB.accdb;"
Dim querystring As String = "select * from cs"
Dim conn As New OleDb.OleDbConnection(connectionstring)
Try
conn.Open()
Dim cmd As New OleDb.OleDbCommand(querystring, conn)
Dim reader As OleDb.OleDbDataReader
reader = cmd.ExecuteReader()
ComboBox1.Items.Clear()
While (reader.Read())
If (ComboBox1.Items.Contains(reader.GetValue(1))) Then
Continue While
Else
ComboBox1.Items.Add(reader.GetValue(1))
End If
End While
reader.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim querystring As String = "select distinct city from cs where province = '" & ComboBox1.Text & " ' "
Try
Using connection As New Odbc.OdbcConnection(connectionstring)
Dim command As New Odbc.OdbcCommand(querystring, connection)
connection.Open()
Dim reader As Odbc.OdbcDataReader = command.ExecuteReader
ComboBox2.Items.Clear()
While reader.Read
ComboBox2.Items.Add(reader.GetValue(0))
End While
reader.Close()
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
如果不加ComboBox1_SelectedIndexChanged这段程序可以正常执行,可加了之后,当选择省时出现错误提示:
ERROR[IM002][Microsoft][ODBC驱动程序管理器]未发现数据源名称并且未指定默认驱动程序
网上有提示要配置数据源的,照做了,但不好用,谁能告诉我为什么?我应该怎么弄?具体一点.如果把VS2010换成2008应该怎么办?
[解决办法]
亲,这里是vb,要到。net区问。