Visual Studio SQL查询无法正常工作

时间:2013-11-11 08:18:47

标签: sql visual-studio

我的SQL查询有问题。问题在于IN ....,但我不知道如何纠正它。这是查询:

SELECT *
FROM Reports, Games, Developers
WHERE Game = SpelID
  AND Developer = IDDvl
  AND Land IN[‘Japan’,‘USA’,‘UK’,‘Indië’,‘Duitsland’,‘Zweden’]

这是错误消息:

An unhandled exception of type 'System.Data.OleDb.OleDbException'
    occurred in System.Data.dll

In operator without () in query expression 'Game = SpelID AND Developer = IDDvl
    AND Land IN [‘Japan’, ‘USA’, ‘UK’, ‘Indië’, ‘Duitsland’, ‘Zweden’]'.

4 个答案:

答案 0 :(得分:3)

    dagoederen = New OleDb.OleDbDataAdapter("SELECT * FROM Reports , Games, 
Developers WHERE Game = SpelID AND Developer = IDDvl AND Land IN (‘Japan’, 
‘USA’, ‘UK’, ‘Indië’, ‘Duitsland’, ‘Zweden’)", connectie)

您需要在[ ]

之后将()替换为IN

答案 1 :(得分:0)

使用右括号和引号:

SELECT * 
FROM Reports , Games, Developers 
WHERE Game = SpelID AND 
      Developer = IDDvl AND 
      Land IN ('Japan', 'USA', 'UK', 'Indië', 'Duitsland', 'Zweden')

答案 2 :(得分:0)

替换为此代码

 Imports System.Data.OleDb
 Public Class Form1
 Private Sub cmdsql1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsql1.Click
connectie.Open()

Dim dagoederen As Data.OleDb.OleDbDataAdapter
 dagoederen = New OleDb.OleDbDataAdapter("SELECT * FROM Reports , Games, Developers WHERE Game = SpelID AND Developer = IDDvl AND Land IN (‘Japan’, ‘USA’, ‘UK’, ‘Indië’, ‘Duitsland’, ‘Zweden’)", connectie)

 Dim dtgoederen As DataSet = New DataSet
 dagoederen.Fill(dtgoederen, "Reports")
 connectie.Close()

 dggoederen.DataSource = dtgoederen.Tables("Reports")
End Sub
End Class

答案 3 :(得分:0)

答案在“查询表达式中没有()的运算符”中提供的错误中指定。对于IN T-SQL

,将“[]”替换为“()”