 |
| .NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 31st, 2008, 10:34 AM
|
|
Registered User
|
|
Join Date: Mar 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Displaying query from three tables
I am using sql server 2000 and vb 2005. I am trying to join three tables programmatically using the inner join SQL statement and display the result on a datagridview, however i am getting an "end of statement expected" error. Please help
|
|

March 31st, 2008, 10:41 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Well there will likely be an error in you SQL. Try getting the SQL to run in Query Analyzer first to get it right.
/- Sam Judson : Wrox Technical Editor -/
|
|

March 31st, 2008, 11:00 AM
|
|
Registered User
|
|
Join Date: Mar 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
the sql statement works ok in query analyzer, but not in vb 2005.
What I need to know, is it possible to display the query from three tables on a datagridview in vb 2005, if it is, what do i need to do?
|
|

March 31st, 2008, 11:06 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
If the SQL can be run in query analyzer then there must be an error in the way you are running it.
Show us the code you are running and we can try to work out what you are doing wrong, but without more to go on its very hard to guess.
/- Sam Judson : Wrox Technical Editor -/
|
|

March 31st, 2008, 01:09 PM
|
|
Registered User
|
|
Join Date: Mar 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Here is the SQL statement that work ok in query analyzer but not in vb 2005.
SELECT table1.table1Field_name, table2.table2Field_name, table3.table3Field_name
FROM table1 INNER JOIN table2 ON table1.table1Field_name = table2.table2Field_name INNER JOIN
table3 ON table2.table2Field_name = table3.table3Field_name
|
|

March 31st, 2008, 01:48 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
Hi there, the SQL looks fine, can you trace the error to the exact line in your code?
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
|
|

March 31st, 2008, 02:45 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Yes, if it works fine in SQL analyzer then it must be an error in the VB code you are using to implement the SQL.
Be careful if concatonating strings that you are leaving spaces at the end of each line
Code:
Dim sql As String = "SELECT table1.table1Field_name, table2.table2Field_name, table3.table3Field_name " _ ' Note space at thend of string
& "FROM table1 INNER JOIN table2 ON table1.table1Field_name = table2.table2Field_name INNER JOIN " _
& "table3 ON table2.table2Field_name = table3.table3Field_name"
Dim conn As New SqlConnection
conn.ConnectionString = "yadayada"
Dim adapter As New SqlDataAdapter
adapter.SelectCommand = new SqlCommand(sql, conn);
Dim ds As New DateSet()
adapter.Fill(ds);
/- Sam Judson : Wrox Technical Editor -/
|
|

April 2nd, 2008, 10:19 AM
|
|
Registered User
|
|
Join Date: Mar 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thx. It was the way I was concatenating the strings. But now I have another error message when filling the dataset
dataAdapter.fill(ds, "dsName")
The error message is "Incorrect syntax near the keyword 'INNER'."
|
|

April 2nd, 2008, 10:47 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Well it looks like there is still an error in the way you are concatenating your strings, as the SQL statement is not valid.
/- Sam Judson : Wrox Technical Editor -/
|
|
 |