I do understand what you're getting at. As several people have pointed out,
there is no way to do that. Also, I believe at least one person put forth
the fact that if you do this:
select a.Customer_ID, b.Customer_ID from ...
The query results will have Customer_ID and Customer_ID1 as the column
names, because a datatable can not have duplicates in the columnnames. I
have also found this to be true. Here's a test to show you how to prove
that.
Public Sub TestColumnsWithSameName()
Dim dt As DataTable
'open the connection
Using cnn As New SqlConnection(My.Settings.myConnectionString)
cnn.Open()
'define the command
Dim cmd As New SqlCommand
cmd.Connection = cnn
cmd.CommandText = "SELECT ProductID, ProductID FROM Product"
'define the data adapter and fill the data table
Dim da As New SqlDataAdapter(cmd)
dt = New DataTable()
da.Fill(dt)
End Using
For Each col As DataColumn In dt.Columns
Debug.Print("column header = " & col.ColumnName)
Next
End Sub
Gives you this output:
column header = ProductID
column header = ProductID1
Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
-----------------------------------------------
vish said:
Hi Robin,
Thanks but I am clerifying my requirement here:
Select a.CustomerID as c_CustomerID, b.CustomerID as o_CustomerID
FROM
Customer a, Orders b where a.whatever = b.whatever.
Here is wht you have written in your example. That's really working
normally. But i was asking that is it possible to trace the
same named columns ( customerID in your example above) without giving
them any aliases. ( i dont want to access them using index of them
too.)
e.g. ( query which i use)
-----------------------------------------------------------------------------------------------------------------------------------------
Select a.CustomerID , b.CustomerID FROM Customer a, Orders b where
a.whatever = b.whatever
and in code,
[language c#]
DataSet dsCustomer; // this contains the single datatable from above
query
string str1,str2;
foreach( DataRow dr in dsCustomer.Table[0].Rows)
{
str1 = (string) dr["CustomerID"]; // This needs to be from table a
str2 = (string) dr["CustomerID"]; // This needs to be from table b
}
-----------------------------------------------------------------------------------------------------------------------------------------
Now the problem I am facing here is str2 always contains the value of
customerID from table a as its first in sequence. I have separate uses
of str1 and str2 values in my code.
This really one of my requirements in my project. I could have gone to
some of the solution given by you people in this post but it may not
be proper for future in my coding and thats why i am looking for the
way to do it.
I hope this will be clearer to you. Thanks to you all who have given
their precious time guiding me.
Vish