vs2005中表名为变量的SQL查询问题
在vs2005中,将数据库的所有表名列在listbox中,想实现的功能是点击某个表名打开此表。现在在sql语句中,查询表名为变量时出错,请各位大虾看看问题出在什么地方?
代码如下:
Private Sub ListBox1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim connectionString As String = GetConnectionString()
Using connection As New SqlConnection(connectionString)
connection.Open()
Dim ds As New Data.DataSet
Dim dap As SqlDataAdapter
Dim test As String
test = "dbo." + ListBox1.SelectedItem
dap = New SqlDataAdapter("select * from " + test, connection)
dap.Fill(ds, "table")
DataGridView1.DataSource = ds
End Using
End Sub --------------------编程问答-------------------- 要指定ds里面的具体表
DataGridView1.DataSource = ds["table"] --------------------编程问答-------------------- 问题应该是出在select语句中吧,因为这段程序对于指定表的静态查询是可以的,换成表名为变量时查询就失败了。 --------------------编程问答-------------------- 解决了,谢谢yuxianye1。
补充:.NET技术 , VB.NET