Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - how to execute query which is use to truen result like pivot table

Reply
 
Old 09-14-2009   #1 (permalink)
mina


 
 

how to execute query which is use to truen result like pivot table

I want to generate pivot table with the help of query view.
SELECT * FROM accessTest PIVOT (Sum(Cash) FOR Ref IN
(POS,BAC,BGC,EBP)) as PivotTable
When i am tring to excute this query in my database it shows me
correct out put.

But when i am trying to execute same query through my vb.net code . it
gives me "syntax error near From statement"
This is my Code.


sQuery = "SELECT * FROM accessTest "
sQuery += " PIVOT (Sum(Cash) FOR Ref"
sQuery += "IN(POS,BAC,BGC,EBP)) as PivotTable"
Dim oCmd As OleDb.OleDbCommand
Dim oConn As OleDb.OleDbConnection
Dim oAdp As OleDb.OleDbDataAdapter
oConn = New OleDbConnection(dbConn)
oCmd = New OleDbCommand
oCmd.Connection = oConn
oCmd.CommandText = sQuery
oCmd.CommandType = CommandType.TableDirect
oAdp = New OleDbDataAdapter(oCmd)
oAdp.Fill(ds, "TT")
DataGridView1.DataSource = ds.Tables(0).DefaultView

My System SpecsSystem Spec
Old 09-23-2009   #2 (permalink)
SMussler


 
 

Re: how to execute query which is use to truen result like pivot table

Looks like you're missing a leading space on the 3rd line in front of first
word " IN(POS..."
or at end of previous line....
Steve M

"mina" <minakshi.patil@newsgroup> wrote in message
news:b5cf1af9-93a9-4da1-9d80-37848862a400@newsgroup
Quote:

>I want to generate pivot table with the help of query view.
> SELECT * FROM accessTest PIVOT (Sum(Cash) FOR Ref IN
> (POS,BAC,BGC,EBP)) as PivotTable
> When i am tring to excute this query in my database it shows me
> correct out put.
>
> But when i am trying to execute same query through my vb.net code . it
> gives me "syntax error near From statement"
> This is my Code.
>
>
> sQuery = "SELECT * FROM accessTest "
> sQuery += " PIVOT (Sum(Cash) FOR Ref"
> sQuery += "IN(POS,BAC,BGC,EBP)) as PivotTable"
> Dim oCmd As OleDb.OleDbCommand
> Dim oConn As OleDb.OleDbConnection
> Dim oAdp As OleDb.OleDbDataAdapter
> oConn = New OleDbConnection(dbConn)
> oCmd = New OleDbCommand
> oCmd.Connection = oConn
> oCmd.CommandText = sQuery
> oCmd.CommandType = CommandType.TableDirect
> oAdp = New OleDbDataAdapter(oCmd)
> oAdp.Fill(ds, "TT")
> DataGridView1.DataSource = ds.Tables(0).DefaultView
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
WMI query results not giving the expected result PowerShell
execute mysql query using vbscript VB Script
how do you create a dynamic table/pivot table .NET General
execute Exchange script from DOS - how to get result? PowerShell
Can't execute T-SQL query PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46