我试图将数据从SQL数据库获取到DataTable
中,但是我被卡住了。
在Excel中它可以工作,但是在VB.net中,以下代码中的'*'附近出现错误:
Dim Strng As String = "SET QUOTED_IDENTIFIER OFF Select Case * From OPENQUERY(INSQL," _
& "'SELECT DateTime = convert(nvarchar, DateTime, 21), [Flow.Value], [Temp.Value], [Phase.PhaseNr]" _
& "FROM WideHistory WHERE wwRetrievalMode = 'Cyclic'" _
& "And wwQualityRule = 'Extended' And wwVersion = 'Latest' And DateTime = GetDate()')"
Dim conn As String = "Data Source=" & "**.**.**.**" & ";" _
& "Initial Catalog=" & "Somedatabase" & ";" _
& "User Id=" & "someone" & ";" _
& "Password=" & "someone" & ";" _
& "Connect Timeout=60;" _
& "Network Library=dbmssocn;"
Dim dtb As New DataTable
Using cnn As New SqlConnection(conn)
cnn.Open()
Using dad As New SqlDataAdapter(Strng, cnn)
dad.Fill(dtb)
End Using
cnn.Close()
End Using
Dim strDetail
For Each row As DataRow In dtb.Rows
strDetail = row.Item("Temp.Value")
Next row
如何解决此问题? 抱歉,该错误出现在此代码行。
dad.Fills(dtb)
我得到的消息是:
类型为System.Data.SqlClient.SqlException的未处理异常” 发生在System.Data.dll
其他信息:“ *”附近的语法不正确。
IP地址不是问题。为了隐私起见,我已将其删除。