views:

30

answers:

2

hi,

Let us think my sql query is

  select customerDetials.custid,TestTable.col1 from CustomerDetails INNER JOIN TestTable  on CustomerDetails.custid=TestTables.custid where CustomerDetails.custid>0

I wanna use OleDbDataReader to retive rows of this .

I used this way

while (dataReader.Read()) { string str= dataReader["customerDetials.custid"].ToString();

}

but the prob is here join is thr so if i give column name like above its throwing me an exception and i cant use index or i cant change the sql query .So is there any way to retrieve the data using the column name

A: 

Have you tried using just

while (dataReader.Read()) { 
    string str= dataReader["custid"].ToString();    
}
astander
yeah ..tried ..but throwing an exception and its not proper also coz join table might also have a col with same name rite ..so it wont be valid.
Bhaswanth
The select is fine. leave that as is. The result returned should have 2 columns, custid and col1.
astander
in this case i dnt have TestTable.custid in query ...think we have it ..coz my query is dynamic i dnt kno how it comes ..so i shud write as general as possible.
Bhaswanth
A: 

I THINK what you want is...

string str = dataReader.GetInt32(0).ToString();

where the (0) refers to the zero-based ordinal position of the columns as in the query

DRapp
i cannot use index based coz i dnt how the query will be prepared so i will not know the order of columns .
Bhaswanth