473,396 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

sql joins in VB

cj
If I have a dataconnection open to a sql server database, can I execute
a sql command containing a join between several tables in that database?

What if I have tables in different databases that I want to join, is
this possible?
Nov 20 '07 #1
5 1869
If I have a dataconnection open to a sql server database, can I execute
a sql command containing a join between several tables in that database?
Yes, just enter it as normal.
What if I have tables in different databases that I want to join, is
this possible?
If you can do it with standard SQL statements then yes. For example
Sql Server supports querying multiple databases, but I don't think you
can join two dbs from different providers. In other words, you should
be able to join two Sql Server databases, but probably not an Oracle
and Sql Server database. If you use strongly typed datasets, you can
use a datarelation object to join two business objects, which sort of
meets your requirement.

Thanks,

Seth Rowe

Nov 20 '07 #2
cj,

To fill a datatable with that is not any problem as long as your SQL
procedure returns one resultset. (You can do it even with more datatables to
one dataset, but then you have to use the mappings).

However don't expect any commandbuilder or generator will do for you the
Update/Delete/Insert commands for you.

Cor

Nov 20 '07 #3
cj
I guess what perplexes me about joining tables from different sql
databases, even if both databases are sql databases on the same sql
server, is I believe both databases would have to have a sqlconnection
and isn't the sqlcommand given only one connection
(mysqlcommand.connection = ...) that it will work for? So how could a
sql query that pulls from multiple databases work?

I know I can write a sql string to do this in sql query analyzer and it
works but I can't see how it would work from VB. Sometimes it might be
necessary.

Here's an example from sql query analyzer

update allanis
set fullname=master.fullname,
street = master.street,
city = master.city,
state = master.state,
zip = master.zip
from amyexcel...allanis$ allanis
inner join trs.dbo.master master
on allanis.btn = master.btn

heck in this query one of the tables is actually an excel spreadsheet
that is added as a linked server.
rowe_newsgroups wrote:
>If I have a dataconnection open to a sql server database, can I execute
a sql command containing a join between several tables in that database?

Yes, just enter it as normal.
>What if I have tables in different databases that I want to join, is
this possible?

If you can do it with standard SQL statements then yes. For example
Sql Server supports querying multiple databases, but I don't think you
can join two dbs from different providers. In other words, you should
be able to join two Sql Server databases, but probably not an Oracle
and Sql Server database. If you use strongly typed datasets, you can
use a datarelation object to join two business objects, which sort of
meets your requirement.

Thanks,

Seth Rowe
Nov 20 '07 #4
Hi,
Per my test, it is also fine to use SqlCommand to execute the T-SQL
statement with linked server. You may refer to the following code:
Dim cn as New
SqlConnection("server=sha-chlwang-2k3\\wow;database=Northwind2k5;Integrated
Security=SSPI")
Dim cmd As New SqlCommand
Dim nRet As Integer
cmd.Connection = cn
cmd.CommandText = "update [master] set
fullname=allanis.fullname,street = allanis.street,city = allanis.city,state
= allanis.state,zip = allanis.zip from amyexcel...master$ [master] inner
join northwind2k5.dbo.allanis on allanis.id = [master].id"
cn.Open()
nRet = cmd.ExecuteNonQuery()
MessageBox.Show(nRet.ToString())
cn.Close()

The above VB code is converted from C#. If there is anything mistake,
please feel free to point out. Hope this helps. If you have any other
questions or concerns, please feel free to let me know.

Best regards,
Charles Wang
Microsoft Online Community Support
================================================== ===
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
================================================== ====
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== ====


Nov 21 '07 #5
if you need to join datas from different providers, there are 2 ways i
found:
1 add all but one to the one (must be SqlServer Enterprise). As i know,
SqlServer 2005 can add other's database like a mirror, even from DB2.
2 join them by code (must use VB9.0 / .net 3.
"cj" <cj@nospam.nospamwrote in message
news:el**************@TK2MSFTNGP02.phx.gbl...
If I have a dataconnection open to a sql server database, can I execute a
sql command containing a join between several tables in that database?

What if I have tables in different databases that I want to join, is this
possible?
Nov 22 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: jgalzic | last post by:
Hi, I'm having trouble doing joins correctly on two tables. I've read up a lot about the different types of joins and tried lots of variations on inner, outer, and left joins with no avail....
3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
4
by: Sri | last post by:
I am writing a download process in which i have a condition where i need to join four tables. Each table have lot of data say around 300000 recs. my question is when i am doing the joins on...
1
by: Prem | last post by:
Hi All Database Gurus, I am trying to write code which will produce all the possible valid queries, given tables and join information for tables. Right now i am just trying to construct all the...
4
by: jbm05 | last post by:
Hi, I'm curious about the computational complexity of a query I have. The query contains multiple nested self left joins, starting with a simple select, then doing a self left join with the...
4
by: michaelnewport | last post by:
Greetings, I like to write my inner joins as below, but someone at work tells me its not as 'performant' as using the 'inner join' statement. Is this true ? Is there a better way to write it...
7
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
2
by: narendra vuradi | last post by:
Hi I have a requirement where in i haev to convert the SQL from Oracle to the one which will run on the SQL server. in the Oracle Query i am doing multiple joins, between some 13 tables. and...
9
by: shapper | last post by:
Hello, I am used to SQL but I am starting to use LINQ. How can I create Left, Right and Inner joins in LINQ? How to distinguish the different joins? Here is a great SQL example:...
36
by: TC | last post by:
I've used Access for many years. Several times, I've encountered a bug which I refer to as the "Vanishing Joins" bug. When it happens, joins vanish randomly from queries. More specifically, all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.