Problem to import data from SQL-DataBase to DataTable










1















I trying to get data from SQL DataBase into a DataTable but I am stuck.

In Excel it works but in VB.net I get an error in near '*' in the folowing code:



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


How can I solve this problem?
Sorry to mention is that the error appears at this line of code.



dad.Fills(dtb)


And The message I get is:




An unhandled exception of type System.Data.SqlClient.SqlException'
occurred in System.Data.dll




Additional information: Incorrect syntax near '*'.



The IP-adress is not the problem. I have removed that for privacy.










share|improve this question
























  • Hi Peter, could you edit your question to include the exception type and message that you're seeing

    – Neil
    Nov 15 '18 at 13:23











  • " Select Case * " is not correct. For what purpose do you use that "case"? Use just " SELECT * FROM... "

    – Jortx
    Nov 15 '18 at 13:28












  • I use 'Case' because i want to get more then 1 values from different items So as you can see [Flow.value],[Temp.value] and [Phase.Phasenr] those are in different items. but same rows.

    – Peter Duivesteijn
    Nov 15 '18 at 13:43







  • 1





    Hi thanks for the help, i solved the problem by removing ** 'Case'** and the following WideHistory WHERE wwRetrievalMode = 'Cyclic' And wwQualityRule = 'Extended' And wwVersion = 'Latest' And from the query now the datatable is filled with the data that i also get in Excel.

    – Peter Duivesteijn
    Nov 15 '18 at 14:06






  • 1





    When you solve a problem, post an answer and accept it. Don't put the word "solved" in the title. The system keeps track of which questions have been answered, and it doesn't look for the word "solved" in the title.

    – Raymond Chen
    Nov 15 '18 at 15:43















1















I trying to get data from SQL DataBase into a DataTable but I am stuck.

In Excel it works but in VB.net I get an error in near '*' in the folowing code:



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


How can I solve this problem?
Sorry to mention is that the error appears at this line of code.



dad.Fills(dtb)


And The message I get is:




An unhandled exception of type System.Data.SqlClient.SqlException'
occurred in System.Data.dll




Additional information: Incorrect syntax near '*'.



The IP-adress is not the problem. I have removed that for privacy.










share|improve this question
























  • Hi Peter, could you edit your question to include the exception type and message that you're seeing

    – Neil
    Nov 15 '18 at 13:23











  • " Select Case * " is not correct. For what purpose do you use that "case"? Use just " SELECT * FROM... "

    – Jortx
    Nov 15 '18 at 13:28












  • I use 'Case' because i want to get more then 1 values from different items So as you can see [Flow.value],[Temp.value] and [Phase.Phasenr] those are in different items. but same rows.

    – Peter Duivesteijn
    Nov 15 '18 at 13:43







  • 1





    Hi thanks for the help, i solved the problem by removing ** 'Case'** and the following WideHistory WHERE wwRetrievalMode = 'Cyclic' And wwQualityRule = 'Extended' And wwVersion = 'Latest' And from the query now the datatable is filled with the data that i also get in Excel.

    – Peter Duivesteijn
    Nov 15 '18 at 14:06






  • 1





    When you solve a problem, post an answer and accept it. Don't put the word "solved" in the title. The system keeps track of which questions have been answered, and it doesn't look for the word "solved" in the title.

    – Raymond Chen
    Nov 15 '18 at 15:43













1












1








1








I trying to get data from SQL DataBase into a DataTable but I am stuck.

In Excel it works but in VB.net I get an error in near '*' in the folowing code:



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


How can I solve this problem?
Sorry to mention is that the error appears at this line of code.



dad.Fills(dtb)


And The message I get is:




An unhandled exception of type System.Data.SqlClient.SqlException'
occurred in System.Data.dll




Additional information: Incorrect syntax near '*'.



The IP-adress is not the problem. I have removed that for privacy.










share|improve this question
















I trying to get data from SQL DataBase into a DataTable but I am stuck.

In Excel it works but in VB.net I get an error in near '*' in the folowing code:



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


How can I solve this problem?
Sorry to mention is that the error appears at this line of code.



dad.Fills(dtb)


And The message I get is:




An unhandled exception of type System.Data.SqlClient.SqlException'
occurred in System.Data.dll




Additional information: Incorrect syntax near '*'.



The IP-adress is not the problem. I have removed that for privacy.







vb.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 16:19









Jimi

9,03741934




9,03741934










asked Nov 15 '18 at 13:13









Peter DuivesteijnPeter Duivesteijn

62




62












  • Hi Peter, could you edit your question to include the exception type and message that you're seeing

    – Neil
    Nov 15 '18 at 13:23











  • " Select Case * " is not correct. For what purpose do you use that "case"? Use just " SELECT * FROM... "

    – Jortx
    Nov 15 '18 at 13:28












  • I use 'Case' because i want to get more then 1 values from different items So as you can see [Flow.value],[Temp.value] and [Phase.Phasenr] those are in different items. but same rows.

    – Peter Duivesteijn
    Nov 15 '18 at 13:43







  • 1





    Hi thanks for the help, i solved the problem by removing ** 'Case'** and the following WideHistory WHERE wwRetrievalMode = 'Cyclic' And wwQualityRule = 'Extended' And wwVersion = 'Latest' And from the query now the datatable is filled with the data that i also get in Excel.

    – Peter Duivesteijn
    Nov 15 '18 at 14:06






  • 1





    When you solve a problem, post an answer and accept it. Don't put the word "solved" in the title. The system keeps track of which questions have been answered, and it doesn't look for the word "solved" in the title.

    – Raymond Chen
    Nov 15 '18 at 15:43

















  • Hi Peter, could you edit your question to include the exception type and message that you're seeing

    – Neil
    Nov 15 '18 at 13:23











  • " Select Case * " is not correct. For what purpose do you use that "case"? Use just " SELECT * FROM... "

    – Jortx
    Nov 15 '18 at 13:28












  • I use 'Case' because i want to get more then 1 values from different items So as you can see [Flow.value],[Temp.value] and [Phase.Phasenr] those are in different items. but same rows.

    – Peter Duivesteijn
    Nov 15 '18 at 13:43







  • 1





    Hi thanks for the help, i solved the problem by removing ** 'Case'** and the following WideHistory WHERE wwRetrievalMode = 'Cyclic' And wwQualityRule = 'Extended' And wwVersion = 'Latest' And from the query now the datatable is filled with the data that i also get in Excel.

    – Peter Duivesteijn
    Nov 15 '18 at 14:06






  • 1





    When you solve a problem, post an answer and accept it. Don't put the word "solved" in the title. The system keeps track of which questions have been answered, and it doesn't look for the word "solved" in the title.

    – Raymond Chen
    Nov 15 '18 at 15:43
















Hi Peter, could you edit your question to include the exception type and message that you're seeing

– Neil
Nov 15 '18 at 13:23





Hi Peter, could you edit your question to include the exception type and message that you're seeing

– Neil
Nov 15 '18 at 13:23













" Select Case * " is not correct. For what purpose do you use that "case"? Use just " SELECT * FROM... "

– Jortx
Nov 15 '18 at 13:28






" Select Case * " is not correct. For what purpose do you use that "case"? Use just " SELECT * FROM... "

– Jortx
Nov 15 '18 at 13:28














I use 'Case' because i want to get more then 1 values from different items So as you can see [Flow.value],[Temp.value] and [Phase.Phasenr] those are in different items. but same rows.

– Peter Duivesteijn
Nov 15 '18 at 13:43






I use 'Case' because i want to get more then 1 values from different items So as you can see [Flow.value],[Temp.value] and [Phase.Phasenr] those are in different items. but same rows.

– Peter Duivesteijn
Nov 15 '18 at 13:43





1




1





Hi thanks for the help, i solved the problem by removing ** 'Case'** and the following WideHistory WHERE wwRetrievalMode = 'Cyclic' And wwQualityRule = 'Extended' And wwVersion = 'Latest' And from the query now the datatable is filled with the data that i also get in Excel.

– Peter Duivesteijn
Nov 15 '18 at 14:06





Hi thanks for the help, i solved the problem by removing ** 'Case'** and the following WideHistory WHERE wwRetrievalMode = 'Cyclic' And wwQualityRule = 'Extended' And wwVersion = 'Latest' And from the query now the datatable is filled with the data that i also get in Excel.

– Peter Duivesteijn
Nov 15 '18 at 14:06




1




1





When you solve a problem, post an answer and accept it. Don't put the word "solved" in the title. The system keeps track of which questions have been answered, and it doesn't look for the word "solved" in the title.

– Raymond Chen
Nov 15 '18 at 15:43





When you solve a problem, post an answer and accept it. Don't put the word "solved" in the title. The system keeps track of which questions have been answered, and it doesn't look for the word "solved" in the title.

– Raymond Chen
Nov 15 '18 at 15:43












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320313%2fproblem-to-import-data-from-sql-database-to-datatable%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320313%2fproblem-to-import-data-from-sql-database-to-datatable%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線