473,386 Members | 1,705 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,386 software developers and data experts.

How to show in a datagrid columns of different datatables?

I have this
i need to show the datagrid with columns of 2 datatables
Dim myadap As New SqlDataAdapter

myconn.Open()

myadap.TableMappings().Add("Table", "vistaUsuarios")

Dim mysqlcmd As New SqlCommand("select * from vistaUsuarios order by
strnombre asc", myconn)

mysqlcmd.CommandType = CommandType.Text

myadap.SelectCommand = mysqlcmd

myadap.Fill(myds)

myconn.Close()

Dim myadapccos As New SqlDataAdapter

myconn2.Open()

myadapccos.TableMappings.Add("Table", "gn_ccost")

Dim mysqlcmdcos As New SqlCommand("select * from gn_ccost", myconn2)

mysqlcmdcos.CommandType = CommandType.Text

myadapccos.SelectCommand = mysqlcmdcos

myadapccos.Fill(myds)

myconn2.Close()

Dim dr As DataRelation

Dim dc1 As DataColumn

Dim dc2 As DataColumn

dc1 = myds.Tables("vistausuarios").Columns("strIdCentroC osto")

dc2 = myds.Tables("gn_ccos").Columns("cos_ccos")

dr = New System.Data.DataRelation("EmpleadosCentros", dc1, dc2)

myds.Relations.Add(dr)


--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEV
Nov 18 '05 #1
7 1596
Sorry, I don't totally understand the question. Can you be more specific as
to what you're trying to do? Based on your comments, I'm guessing you're
trying to handle a parent/child relationship in the same grid, in which case
it's usually easier to create a *single* datasource, either by doing a join
on the server side, or by doing the selects as you're doing them and adding
the result of the one as a new datacolumn to the other. You can format the
new data either when you add it to the datasource, or at run-time via
ItemDataBound.

Bill

"Luis Esteban Valencia" wrote:
I have this
i need to show the datagrid with columns of 2 datatables
Dim myadap As New SqlDataAdapter

myconn.Open()

myadap.TableMappings().Add("Table", "vistaUsuarios")

Dim mysqlcmd As New SqlCommand("select * from vistaUsuarios order by
strnombre asc", myconn)

mysqlcmd.CommandType = CommandType.Text

myadap.SelectCommand = mysqlcmd

myadap.Fill(myds)

myconn.Close()

Dim myadapccos As New SqlDataAdapter

myconn2.Open()

myadapccos.TableMappings.Add("Table", "gn_ccost")

Dim mysqlcmdcos As New SqlCommand("select * from gn_ccost", myconn2)

mysqlcmdcos.CommandType = CommandType.Text

myadapccos.SelectCommand = mysqlcmdcos

myadapccos.Fill(myds)

myconn2.Close()

Dim dr As DataRelation

Dim dc1 As DataColumn

Dim dc2 As DataColumn

dc1 = myds.Tables("vistausuarios").Columns("strIdCentroC osto")

dc2 = myds.Tables("gn_ccos").Columns("cos_ccos")

dr = New System.Data.DataRelation("EmpleadosCentros", dc1, dc2)

myds.Relations.Add(dr)


--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEV

Nov 18 '05 #2
Can't you use a JOIN in the SQL call to get the two tables to one dataset?

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Luis Esteban Valencia" <lu*******@haceb.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have this
i need to show the datagrid with columns of 2 datatables
Dim myadap As New SqlDataAdapter

myconn.Open()

myadap.TableMappings().Add("Table", "vistaUsuarios")

Dim mysqlcmd As New SqlCommand("select * from vistaUsuarios order by
strnombre asc", myconn)

mysqlcmd.CommandType = CommandType.Text

myadap.SelectCommand = mysqlcmd

myadap.Fill(myds)

myconn.Close()

Dim myadapccos As New SqlDataAdapter

myconn2.Open()

myadapccos.TableMappings.Add("Table", "gn_ccost")

Dim mysqlcmdcos As New SqlCommand("select * from gn_ccost", myconn2)

mysqlcmdcos.CommandType = CommandType.Text

myadapccos.SelectCommand = mysqlcmdcos

myadapccos.Fill(myds)

myconn2.Close()

Dim dr As DataRelation

Dim dc1 As DataColumn

Dim dc2 As DataColumn

dc1 = myds.Tables("vistausuarios").Columns("strIdCentroC osto")

dc2 = myds.Tables("gn_ccos").Columns("cos_ccos")

dr = New System.Data.DataRelation("EmpleadosCentros", dc1, dc2)

myds.Relations.Add(dr)


--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEV

Nov 18 '05 #3
I cant do the Join on the sql server because one server cant be LINKED to
the another server.

--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEV
"Bill Borg" <Bi******@discussions.microsoft.com> escribió en el mensaje
news:13**********************************@microsof t.com...
Sorry, I don't totally understand the question. Can you be more specific as to what you're trying to do? Based on your comments, I'm guessing you're
trying to handle a parent/child relationship in the same grid, in which case it's usually easier to create a *single* datasource, either by doing a join on the server side, or by doing the selects as you're doing them and adding the result of the one as a new datacolumn to the other. You can format the
new data either when you add it to the datasource, or at run-time via
ItemDataBound.

Bill

"Luis Esteban Valencia" wrote:
I have this
i need to show the datagrid with columns of 2 datatables
Dim myadap As New SqlDataAdapter

myconn.Open()

myadap.TableMappings().Add("Table", "vistaUsuarios")

Dim mysqlcmd As New SqlCommand("select * from vistaUsuarios order by
strnombre asc", myconn)

mysqlcmd.CommandType = CommandType.Text

myadap.SelectCommand = mysqlcmd

myadap.Fill(myds)

myconn.Close()

Dim myadapccos As New SqlDataAdapter

myconn2.Open()

myadapccos.TableMappings.Add("Table", "gn_ccost")

Dim mysqlcmdcos As New SqlCommand("select * from gn_ccost", myconn2)

mysqlcmdcos.CommandType = CommandType.Text

myadapccos.SelectCommand = mysqlcmdcos

myadapccos.Fill(myds)

myconn2.Close()

Dim dr As DataRelation

Dim dc1 As DataColumn

Dim dc2 As DataColumn

dc1 = myds.Tables("vistausuarios").Columns("strIdCentroC osto")

dc2 = myds.Tables("gn_ccos").Columns("cos_ccos")

dr = New System.Data.DataRelation("EmpleadosCentros", dc1, dc2)

myds.Relations.Add(dr)


--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEV

Nov 18 '05 #4
No becase the servers cant be linked I have full access to one server and
only reading to the another server.

--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEV
"Curt_C [MVP]" <software_AT_darkfalz.com> escribió en el mensaje
news:uK**************@TK2MSFTNGP15.phx.gbl...
Can't you use a JOIN in the SQL call to get the two tables to one dataset?

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Luis Esteban Valencia" <lu*******@haceb.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have this
i need to show the datagrid with columns of 2 datatables
Dim myadap As New SqlDataAdapter

myconn.Open()

myadap.TableMappings().Add("Table", "vistaUsuarios")

Dim mysqlcmd As New SqlCommand("select * from vistaUsuarios order by
strnombre asc", myconn)

mysqlcmd.CommandType = CommandType.Text

myadap.SelectCommand = mysqlcmd

myadap.Fill(myds)

myconn.Close()

Dim myadapccos As New SqlDataAdapter

myconn2.Open()

myadapccos.TableMappings.Add("Table", "gn_ccost")

Dim mysqlcmdcos As New SqlCommand("select * from gn_ccost", myconn2)

mysqlcmdcos.CommandType = CommandType.Text

myadapccos.SelectCommand = mysqlcmdcos

myadapccos.Fill(myds)

myconn2.Close()

Dim dr As DataRelation

Dim dc1 As DataColumn

Dim dc2 As DataColumn

dc1 = myds.Tables("vistausuarios").Columns("strIdCentroC osto")

dc2 = myds.Tables("gn_ccos").Columns("cos_ccos")

dr = New System.Data.DataRelation("EmpleadosCentros", dc1, dc2)

myds.Relations.Add(dr)


--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEV


Nov 18 '05 #5
If you can't do the join, then just do the two selects as you're doing, but
add the columns from the second dataset to the first in your code.

Is this a parent/child relationship, or a one-to-one? It doesn't really
matter, but if it's a parent/child you need to think about how you want to
traverse the child data (what I'll do in simple cases is add the child data
as a single string to each parent row, e.g. Customer is the parent, Invoices
is the child, and add a string like Invoice 1<br>Invoice 2<br>Invoice 3<br>,
etc. to the parent row).

Bill

"Luis Esteban Valencia" wrote:
I cant do the Join on the sql server because one server cant be LINKED to
the another server.

--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEV
"Bill Borg" <Bi******@discussions.microsoft.com> escribió en el mensaje
news:13**********************************@microsof t.com...
Sorry, I don't totally understand the question. Can you be more specific

as
to what you're trying to do? Based on your comments, I'm guessing you're
trying to handle a parent/child relationship in the same grid, in which

case
it's usually easier to create a *single* datasource, either by doing a

join
on the server side, or by doing the selects as you're doing them and

adding
the result of the one as a new datacolumn to the other. You can format the
new data either when you add it to the datasource, or at run-time via
ItemDataBound.

Bill

"Luis Esteban Valencia" wrote:
I have this
i need to show the datagrid with columns of 2 datatables
Dim myadap As New SqlDataAdapter

myconn.Open()

myadap.TableMappings().Add("Table", "vistaUsuarios")

Dim mysqlcmd As New SqlCommand("select * from vistaUsuarios order by
strnombre asc", myconn)

mysqlcmd.CommandType = CommandType.Text

myadap.SelectCommand = mysqlcmd

myadap.Fill(myds)

myconn.Close()

Dim myadapccos As New SqlDataAdapter

myconn2.Open()

myadapccos.TableMappings.Add("Table", "gn_ccost")

Dim mysqlcmdcos As New SqlCommand("select * from gn_ccost", myconn2)

mysqlcmdcos.CommandType = CommandType.Text

myadapccos.SelectCommand = mysqlcmdcos

myadapccos.Fill(myds)

myconn2.Close()

Dim dr As DataRelation

Dim dc1 As DataColumn

Dim dc2 As DataColumn

dc1 = myds.Tables("vistausuarios").Columns("strIdCentroC osto")

dc2 = myds.Tables("gn_ccos").Columns("cos_ccos")

dr = New System.Data.DataRelation("EmpleadosCentros", dc1, dc2)

myds.Relations.Add(dr)


--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEV


Nov 18 '05 #6
Please tell me the code to do that

Add columns from datattable gn_ccost to the datatable vistaempleados.

Thanks

"Bill Borg" <Bi******@discussions.microsoft.com> escribió en el mensaje
news:F2**********************************@microsof t.com...
If you can't do the join, then just do the two selects as you're doing, but add the columns from the second dataset to the first in your code.

Is this a parent/child relationship, or a one-to-one? It doesn't really
matter, but if it's a parent/child you need to think about how you want to
traverse the child data (what I'll do in simple cases is add the child data as a single string to each parent row, e.g. Customer is the parent, Invoices is the child, and add a string like Invoice 1<br>Invoice 2<br>Invoice 3<br>, etc. to the parent row).

Bill

"Luis Esteban Valencia" wrote:
I cant do the Join on the sql server because one server cant be LINKED to the another server.

--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEV
"Bill Borg" <Bi******@discussions.microsoft.com> escribió en el mensaje
news:13**********************************@microsof t.com...
Sorry, I don't totally understand the question. Can you be more specific
as
to what you're trying to do? Based on your comments, I'm guessing
you're trying to handle a parent/child relationship in the same grid, in which case
it's usually easier to create a *single* datasource, either by doing a

join
on the server side, or by doing the selects as you're doing them and

adding
the result of the one as a new datacolumn to the other. You can format

the new data either when you add it to the datasource, or at run-time via
ItemDataBound.

Bill

"Luis Esteban Valencia" wrote:

> I have this
> i need to show the datagrid with columns of 2 datatables
>
>
> Dim myadap As New SqlDataAdapter
>
> myconn.Open()
>
> myadap.TableMappings().Add("Table", "vistaUsuarios")
>
> Dim mysqlcmd As New SqlCommand("select * from vistaUsuarios order by
> strnombre asc", myconn)
>
> mysqlcmd.CommandType = CommandType.Text
>
> myadap.SelectCommand = mysqlcmd
>
> myadap.Fill(myds)
>
> myconn.Close()
>
>
>
> Dim myadapccos As New SqlDataAdapter
>
> myconn2.Open()
>
> myadapccos.TableMappings.Add("Table", "gn_ccost")
>
> Dim mysqlcmdcos As New SqlCommand("select * from gn_ccost", myconn2)
>
> mysqlcmdcos.CommandType = CommandType.Text
>
> myadapccos.SelectCommand = mysqlcmdcos
>
> myadapccos.Fill(myds)
>
> myconn2.Close()
>
> Dim dr As DataRelation
>
> Dim dc1 As DataColumn
>
> Dim dc2 As DataColumn
>
> dc1 = myds.Tables("vistausuarios").Columns("strIdCentroC osto")
>
> dc2 = myds.Tables("gn_ccos").Columns("cos_ccos")
>
> dr = New System.Data.DataRelation("EmpleadosCentros", dc1, dc2)
>
> myds.Relations.Add(dr)
>
>
>
>
>
>
>
>
> --
> LUIS ESTEBAN VALENCIA
> MICROSOFT DCE 2.
> MIEMBRO ACTIVO DE ALIANZADEV
>
>
>


Nov 18 '05 #7
I'm still not sure how your tables are related, but here's one "manual" way
to do what I mean (vb syntax):

' Add a column to your main table. Each row will be initialized to null.
Check out
' overrides of datacolumn() to create columns of certain data type, etc.
Also look
' at using AddRange instead of Add.
Dim dt As DataTable = YourDataTable1
dt.Columns.Add(New DataColumn("MyNewColumn"))

' Loop through the rows in your main table, go get the matching child data,
and add
' it to the new column(s) for that row.
For Each dr As DataRow In dt.Rows
dr("MyNewColumn") = "My additional data for this row"
Next

There are more efficient ways of doing this, but if your datatables are
reasonably small this will be fine. Check out dataset.merge for one. Also,
using datarelations will probably help.

hth,

Bill

"Luis Esteban Valencia" wrote:
Please tell me the code to do that

Add columns from datattable gn_ccost to the datatable vistaempleados.

Thanks

"Bill Borg" <Bi******@discussions.microsoft.com> escribió en el mensaje
news:F2**********************************@microsof t.com...
If you can't do the join, then just do the two selects as you're doing,

but
add the columns from the second dataset to the first in your code.

Is this a parent/child relationship, or a one-to-one? It doesn't really
matter, but if it's a parent/child you need to think about how you want to
traverse the child data (what I'll do in simple cases is add the child

data
as a single string to each parent row, e.g. Customer is the parent,

Invoices
is the child, and add a string like Invoice 1<br>Invoice 2<br>Invoice

3<br>,
etc. to the parent row).

Bill

"Luis Esteban Valencia" wrote:
I cant do the Join on the sql server because one server cant be LINKED to the another server.

--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 2.
MIEMBRO ACTIVO DE ALIANZADEV
"Bill Borg" <Bi******@discussions.microsoft.com> escribió en el mensaje
news:13**********************************@microsof t.com...
> Sorry, I don't totally understand the question. Can you be more specific as
> to what you're trying to do? Based on your comments, I'm guessing you're > trying to handle a parent/child relationship in the same grid, in which case
> it's usually easier to create a *single* datasource, either by doing a
join
> on the server side, or by doing the selects as you're doing them and
adding
> the result of the one as a new datacolumn to the other. You can format the > new data either when you add it to the datasource, or at run-time via
> ItemDataBound.
>
> Bill
>
> "Luis Esteban Valencia" wrote:
>
> > I have this
> > i need to show the datagrid with columns of 2 datatables
> >
> >
> > Dim myadap As New SqlDataAdapter
> >
> > myconn.Open()
> >
> > myadap.TableMappings().Add("Table", "vistaUsuarios")
> >
> > Dim mysqlcmd As New SqlCommand("select * from vistaUsuarios order by
> > strnombre asc", myconn)
> >
> > mysqlcmd.CommandType = CommandType.Text
> >
> > myadap.SelectCommand = mysqlcmd
> >
> > myadap.Fill(myds)
> >
> > myconn.Close()
> >
> >
> >
> > Dim myadapccos As New SqlDataAdapter
> >
> > myconn2.Open()
> >
> > myadapccos.TableMappings.Add("Table", "gn_ccost")
> >
> > Dim mysqlcmdcos As New SqlCommand("select * from gn_ccost", myconn2)
> >
> > mysqlcmdcos.CommandType = CommandType.Text
> >
> > myadapccos.SelectCommand = mysqlcmdcos
> >
> > myadapccos.Fill(myds)
> >
> > myconn2.Close()
> >
> > Dim dr As DataRelation
> >
> > Dim dc1 As DataColumn
> >
> > Dim dc2 As DataColumn
> >
> > dc1 = myds.Tables("vistausuarios").Columns("strIdCentroC osto")
> >
> > dc2 = myds.Tables("gn_ccos").Columns("cos_ccos")
> >
> > dr = New System.Data.DataRelation("EmpleadosCentros", dc1, dc2)
> >
> > myds.Relations.Add(dr)
> >
> >
> >
> >
> >
> >
> >
> >
> > --
> > LUIS ESTEBAN VALENCIA
> > MICROSOFT DCE 2.
> > MIEMBRO ACTIVO DE ALIANZADEV
> >
> >
> >


Nov 18 '05 #8

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

Similar topics

4
by: ETX | last post by:
Hello, My question is about the datagrid sorting. I have a datatable that is filled up with the data retrieved from an SQL query.I use that datatable as source for my datagrid. I would like to...
3
by: Kevin | last post by:
Hi Al I want to add two combobox columns in my datagrid. the one combobox column must be bound to the same datasource that the datagrid is, and the other combobox I just want to populate with a...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
1
by: strongmace | last post by:
Hi. I'm rather new to vs.net so explaining things in detail would be of great help to me. I'm working on a WebForms Project. Basically I have a datagrid I need to populate. I have it set up so...
16
by: stojilcoviz | last post by:
I've a datagrid whose datasource is an arraylist object. The arraylist holds many instances of a specific class. I've two questions about this: 1 - Is there a way by which I can obtain a...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
4
by: Mortar | last post by:
i need a datagrid with 2 header columns. The top one might have 1 column spanning 5 columns of the header row below it. what is the best way to do this? Could i have 2 datatables...1 filling the...
4
by: Rich | last post by:
Hello, I have a one datagrid that will be based on different datatables. One datatable may have 7 columns, another 15... With the tables that have more columns, I have been manually dragging...
2
by: Thomas Beyerlein | last post by:
Is it possible to have different columns of a datagrid bound to different datatables? I am working on a project and the specks have suddenly changed. Now a item can have multiple reports/...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.