请教::hamadou(闵峰)大哥代码中的一点问题。高手给指点下

kingonlyme 2005-06-06 08:06:40
Private ds As New DataSet()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cmd1 As New SqlCommand("select * from province", SqlCon)

“这里的sqlcon是什么?我用的是access库,总提示没有声明。我换过cn(cn="Provider=Microsoft.Jet.OLEDB.4.0;Data source=..\股票.mdb").可是提示 类型“String”的值无法转换为“System.Data.SqlClient.SqlConnection”。高手指点啊

Dim cmd2 As New SqlCommand("select * from city", SqlCon)
Dim cmd3 As New SqlCommand("select * from county ", SqlCon)
Dim dpr1 As New SqlDataAdapter(cmd1)
Dim dpr2 As New SqlDataAdapter(cmd2)
Dim dpr3 As New SqlDataAdapter(cmd3)
dpr1.Fill(ds, "province")
dpr2.Fill(ds, "city")
dpr3.Fill(ds, "county")
Me.ComboBox1.DataSource = ds.Tables("province")
Me.ComboBox1.DisplayMember = "pname"
Me.ComboBox1.ValueMember = "pid"
setdata()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If Not Me.ComboBox1.Focus Then Exit Sub
setdata()
End Sub
Private Sub setdata()
Dim pid As Integer = Me.ComboBox1.SelectedValue
Dim view As New DataView(ds.Tables("city"), "pid=" & CStr(pid), "pid", DataViewRowState.CurrentRows)
If view.Count < 1 Then
Me.ComboBox2.DataSource = Nothing
Me.ComboBox2.Items.Clear()
Me.ComboBox2.SelectAll()
Me.ComboBox2.Focus()
SendKeys.Send("{delete}")

Else
Me.ComboBox2.DataSource = Nothing
Me.ComboBox2.DataSource = view
Me.ComboBox2.DisplayMember = "cname"
Me.ComboBox2.ValueMember = "cid"
End If

End Sub
...全文
42 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
kingonlyme 2005-06-06
sunjian_qi(sonne) 兄:有QQ号吗?我想以后请教一些问题方便些哈
我快答辩了~~毕业设计还没影那!!呵呵~~
帮帮忙~~感谢
回复
kingonlyme 2005-06-06
十分感谢sunjian_qi(sonne)兄:)
可以拉:)
回复
sunjian_qi 2005-06-06
SqlCommand改成OleDbCommand
SqlDataAdapter改成OleDbDataAdapter
回复
kingonlyme 2005-06-06
我试了啊~~怎么还不行啊
Dim cn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=..\股票.mdb"
Dim SqlCon As New OleDbConnection(cn)
Dim cmd1 As New SqlCommand("select * from province", SqlCon)
还是提示:::类型“String”的值无法转换为“System.Data.SqlClient.SqlConnection
回复
sunjian_qi 2005-06-06
sorry,应该用OleDbConnection,大意了,呵呵!
回复
sunjian_qi 2005-06-06
这里的SqlCon是指一个SqlConnection类的实例,在
Dim cmd1 As New SqlCommand("select * from province", SqlCon)
之前你要声明
Dim cn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=..\股票.mdb"
Dim SqlConn As New SqlConnection(cn)
回复
fanruinet 2005-06-06
用access数据库不能用Sql开头的类,要用Oledb开头的类
回复
相关推荐
发帖
VB
创建于2007-09-28

1.6w+

社区成员

VB技术相关讨论,主要为经典vb,即VB6.0
申请成为版主
帖子事件
创建了帖子
2005-06-06 08:06
社区公告
暂无公告