在vs2010里连接sql数据库时对象名无效
在编程时,连接sql数据库时出现实时错误对象名无效,查了许多,说得是五花八门,有没有大神帮我看下的,纠结了好多天,一直没办法解决,下面这是程序代码PublicmycnnA...
在编程时,连接sql数据库时出现实时错误对象名无效,查了许多,说得是五花八门,有没有大神帮我看下的,纠结了好多天,一直没办法解决,下面这是程序代码
Public mycnn As String = "Data Source=DINGLI-PC;Initial Catalog=大坝结构数据SQL;Integrated Security=True"
Public GridViewAdapter As New SqlDataAdapter
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim 坝段号传 As String
Dim GridViewSet As New DataSet
Dim GridViewCom As New SqlCommand
Dim GridViewCon As New SqlConnection(mycnn)
GridViewCon.Open()
坝段号传 = ComboBox1.Text
Dim GridViewAdapter = New SqlDataAdapter("select * from 坝段号传", GridViewCon)
GridViewCon.Close()
GridViewAdapter.Fill(GridViewSet, 坝段号传)
DataGridView1.DataSource = GridViewSet.Tables(坝段号传)
DataGridView1.DataBindings.Add(New Binding("text", GridViewSet, 坝段号传))
一直都是说GridViewAdapter.Fill(GridViewSet, 坝段号传)这个里面的坝段号对象名无效。。。怎么破 展开
Public mycnn As String = "Data Source=DINGLI-PC;Initial Catalog=大坝结构数据SQL;Integrated Security=True"
Public GridViewAdapter As New SqlDataAdapter
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim 坝段号传 As String
Dim GridViewSet As New DataSet
Dim GridViewCom As New SqlCommand
Dim GridViewCon As New SqlConnection(mycnn)
GridViewCon.Open()
坝段号传 = ComboBox1.Text
Dim GridViewAdapter = New SqlDataAdapter("select * from 坝段号传", GridViewCon)
GridViewCon.Close()
GridViewAdapter.Fill(GridViewSet, 坝段号传)
DataGridView1.DataSource = GridViewSet.Tables(坝段号传)
DataGridView1.DataBindings.Add(New Binding("text", GridViewSet, 坝段号传))
一直都是说GridViewAdapter.Fill(GridViewSet, 坝段号传)这个里面的坝段号对象名无效。。。怎么破 展开
展开全部
“select * from 坝段号传”语句是错误的,语句中坝段号传是变量,不是表名,应该变量代入。
追问
你好,那变量是如何带入啊?
追答
Dim GridViewAdapter = New SqlDataAdapter("select * from 坝段号传", GridViewCon)
改为
Dim GridViewAdapter = New SqlDataAdapter("select * from " + 坝段号传, GridViewCon)
2013-10-14
展开全部
你是不是用了其它版的数据库,你用VS2010,数据库也要SQL2010,在看你设置有没有问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询