Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language 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 June 26th, 2009, 09:06 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default How to Join 2 tables in to 1

Hi There

I Have 2 tables and need to get 2 columns from tabel1 and 3 columns from table2.

I Have this So far:
Code:
Dim cmd As SqlCommand = cnn.CreateCommand
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT SLP05.CUSN05, SLP05.CNAM05, SimDefault.SimNet, SimDefault.Cost, SimDefault.Commission FROM SimDefault CROSS JOIN SLP05()WHERE (SLP05.CUSN05 = @CUSN05)"

cmd.Parameters.Add("@CUSN05", Data.SqlDbType.Char, 8).Value = Me.TextBox1.Text
Dim da As SqlDataAdapter = New SqlDataAdapter
da.SelectCommand = cmd
Dim ds As DataSet = New DataSet
da.Fill(ds, "CUSN05")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "CUSN05"
But i get this error:
Parameters supplied for object 'SLP05' which is not a function. If the parameters are intended as a table hint, a WITH keyword is required.

thanks
__________________
bx
 
Old June 26th, 2009, 09:35 AM
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

Hello..
I think that () after SLP05 is useless...
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old June 26th, 2009, 10:22 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

Thanks that was it

gbianchi i have a little question??

How to make the Query to ingnore the spaces ;

I have a text box that you enter the company name than you click search, the SQL command runs to the database and checks 4 the exact match.

i need to search 4 minimum of 5 karacters and % after.

I know that i have to use the LIKE thing but i dont know exactly how >>

can you post something regarding this?

i have this buti it only works with the first letter in the textbox, if i type mor it returns no data
cmd.CommandText = "SELECT SLP05.CNAM05, SLP05.CUSN05, SimDefault.SimNet, SimDefault.Cost, SimDefault.Commission FROM SimDefault CROSS JOIN SLP05 Where (SLP05.CNAM05 Like '" & txtName.Text & " %')"
__________________
bx

Last edited by bex; June 26th, 2009 at 10:46 AM..
 
Old June 26th, 2009, 10:51 AM
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

did you try the querys directly on the database?? the query looks perfectly fine, it should be working (but you have a space before the % that should not be there...
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old June 26th, 2009, 10:58 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

thanks

1 little space :)
__________________
bx
 
Old June 26th, 2009, 11:26 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

Can i pass this to a textbox insted of a DataGrid?
__________________
bx
 
Old June 26th, 2009, 02:21 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

A select??? only if you return only one row/column... and you use executescalar
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old June 26th, 2009, 03:46 PM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

That is not good for me,

I asked that cos i have a print button that i want to print the DataGrid, I got it working with the textbox, but not with the Datagrid, Is there a way to print grid data?
__________________
bx
 
Old June 27th, 2009, 03:24 PM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

gbianchi I Have a Job in SQL 2005 Importing Data From SQL2000. Every time the job runs it imports the data but creates duplicates, how to stop this from creating duplicates?

I Just Need Updates
__________________
bx
 
Old June 27th, 2009, 05:17 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

You are not giving me any information that could help me solve this... you are getting duplicates, but why, I can't tell you without knowing how this thing works, SQL involved, when do it run, etc...
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Join tables help tdaustin Classic ASP Databases 2 January 11th, 2006 04:57 PM
how to join all records from both tables? yixchen Access 4 January 4th, 2006 01:36 PM
how to inner join tables gilgalbiblewheel Classic ASP Databases 4 January 31st, 2005 08:04 PM
Join Tables tdaustin Classic ASP Basics 1 May 25th, 2004 07:31 AM
Inner Join multiple tables qwprince Classic ASP Databases 5 July 23rd, 2003 02:33 PM





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