SqlCommand 无法识别所选表中的列名
我刚刚发布了有关更新连接字符串的上一个问题。它工作正常,但它使我的选择命令失败。 SqlException 被处理为无效的列名 'Username', 'Password', 'UserType'
它们已经在我的数据库中的 User 表中。
下面是我的选择命令:
myConnection = New SqlConnection("Server=RAVY-PC\RAVY;Database=CIEDC;Trusted_Connection=True")
myConnection.Open()
myCommand = New SqlCommand("SELECT UserType FROM User WHERE UserName = @User AND Password = @Pass", myConnection)
txtUserType.Text = myCommand.ExecuteScalar()
由于它捕获了上述错误,我不知道问题是什么。请帮忙。
I just posted a previous question about updating the connection string. It works fine, but it makes my select command fail. The SqlException was handled that Invalid column name 'Username', 'Password', 'UserType'
which they are already in my User table from my database.
Below is my select command:
myConnection = New SqlConnection("Server=RAVY-PC\RAVY;Database=CIEDC;Trusted_Connection=True")
myConnection.Open()
myCommand = New SqlCommand("SELECT UserType FROM User WHERE UserName = @User AND Password = @Pass", myConnection)
txtUserType.Text = myCommand.ExecuteScalar()
Since it catched the above error, I've no idea what was the problem. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试在
User
周围放置方括号来引用表名(User 是关键字):Try placing square backets around
User
to quote the tablename (User is a keyword):您似乎没有设置参数:
It doesn't look like you are setting your parameters:
使用这个:
然后添加参数。
Use this:
Then add parameters.
在列名称周围使用方括号。这将允许关键字用作列名称。例如尝试以下操作。
Use square brackets around your column names. This will allow keywords to be used as column names. Try the following for example.