Wrox Programmer Forums
|
.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
 
Old March 31st, 2008, 10:34 AM
Registered User
 
Join Date: Mar 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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



 
Old March 31st, 2008, 10:41 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/
 
Old March 31st, 2008, 11:00 AM
Registered User
 
Join Date: Mar 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

 
Old March 31st, 2008, 11:06 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/
 
Old March 31st, 2008, 01:09 PM
Registered User
 
Join Date: Mar 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old March 31st, 2008, 01:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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
================================================== =========
 
Old March 31st, 2008, 02:45 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/
 
Old April 2nd, 2008, 10:19 AM
Registered User
 
Join Date: Mar 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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'."

 
Old April 2nd, 2008, 10:47 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
displaying multiple non related tables in gridv shoakat ASP.NET 2.0 Basics 7 September 11th, 2007 04:21 PM
Displaying tables in Visual C++ azhure Visual C++ 0 July 23rd, 2005 03:23 PM
tables not displaying all the rows values... abhit_kumar JSP Basics 2 January 17th, 2005 12:03 AM
tables not displaying all the rows values... abhit_kumar Servlets 0 January 12th, 2005 10:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.