vb.net - 使用数据集填充数据适配器时出错
下面是我的代码:
myCommand = New SqlCommand("SELECT VisitorID, VisitorName, Skill FROM tblVisitor LEFT JOIN tblSkill ON tblVisitor.SkillID = tblSkill.SkillID", myConnection)
myAdapter = New SqlDataAdapter(myCommand)
myAdapter.Fill(myDataSet, "tblVisitor")
tblView.DataSource = myDataSet.Tables(0)
然后它捕获一个错误 In Correct Syntax close".
,它指向 myAdapter.Fill(myDataSet, "tblVisitor")
而不是 Select 命令。
请帮助。
below is my code:
myCommand = New SqlCommand("SELECT VisitorID, VisitorName, Skill FROM tblVisitor LEFT JOIN tblSkill ON tblVisitor.SkillID = tblSkill.SkillID", myConnection)
myAdapter = New SqlDataAdapter(myCommand)
myAdapter.Fill(myDataSet, "tblVisitor")
tblView.DataSource = myDataSet.Tables(0)
then it catch an error as Incorrect Syntax near".
which it points to myAdapter.Fill(myDataSet, "tblVisitor")
not the Select command.
Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
DataAdapter.Fill
上引发异常是正常行为,而不是在构建 SqlCommand 时引发异常。因为Fill
是 ADO.NET 查询数据库的第一个点。“附近语法错误”之后是什么?因为通常数据库会提示你在哪里找到SQL语句中的错误。
如果您的模型与此测试模型类似,您的 SQl 语句似乎是正确的:
结果:
It's a normal behavior that the exception is thrown on
DataAdapter.Fill
and not on building the SqlCommand. BecauseFill
is the first point where ADO.NET will query your database.What comes after "Incorrect syntax near"? Because normally the database will give you a hint where to find the error in SQL-Statement.
Your SQl-Statement seems to be correct if your Model is similar to this test-model:
The result:
您是否为数据集创建了实例?
参考这个
检查这个
have you created instance for your dataset??
refer this
check this