将表名称粘贴为参数
我想将表名称粘贴为函数参数,并且函数需要返回 DataSet,这是我的代码:
Public Function GetTTabele(ByVal tableName As String) As DataSet
Dim DAT As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM tableName", nwindConn)
Dim DAT As DataSet = New DataSet()
DAT.MissingSchemaAction = MissingSchemaAction.AddWithKey
DAT.Fill(DAT, tableName)
GetTTabele = DAT
End Function
现在,当我执行此代码时,我收到下一个错误: System.Data.SqlClient.SqlException:无效的对象名称“tableName”。
I want to paste table name as function parameter and function need to return DataSet, this is the my code for that:
Public Function GetTTabele(ByVal tableName As String) As DataSet
Dim DAT As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM tableName", nwindConn)
Dim DAT As DataSet = New DataSet()
DAT.MissingSchemaAction = MissingSchemaAction.AddWithKey
DAT.Fill(DAT, tableName)
GetTTabele = DAT
End Function
Now when i execute this code I'm getting next error:
System.Data.SqlClient.SqlException: Invalid object name 'tableName'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“SELECT * FROM tableName”
应更改为“SELECT * FROM” & tableName
允许将参数 tableName 的内容附加到字符串“SELECT * FROM”
"SELECT * FROM tableName"
should be changed to "SELECT * FROM " & tableName
allowing the contents of your parameter tableName to be appended to the string "SELECT * FROM "
您的数据库中不存在表“tableName”。指定现有的表名称。
Table "tableName" does not exists on your database. Specify a existing table name.
将代码行更改
为“
您正在尝试查找一个字面意思为“tableName”的表,而不是存储在变量 tableName 中的表名称。
Change the line of code
to read
You are trying to find a table called, literally, "tableName", rather than the table name stored in the variable tableName.