user34537
user34537

Reputation:

Get table name from ADO.NET Field?

If i do a select on user.name, user.post, t.name with t being tag_name AS t is there a way to resolve the full name using ADO.NET?

I found SqlDataReader.GetName but that is getting me only name as the first result. I would like to know if it belongs to user or tag_name. Is there a way to have it tell me?

Upvotes: 1

Views: 853

Answers (3)

Richard Friend
Richard Friend

Reputation: 16018

You could alias your field with the table name as a prefix and read the fieldname and manipulate it in the client..

select a.column1 as [users column1],b.column2 as [tag_name column2] from users a     left join tag_name b on a.col = b.col blah blah....

Upvotes: 2

Carl Rippon
Carl Rippon

Reputation: 4673

Ray is correct in that ado.net doesn't give you this. What I have done in the past is to get the SQL from the stored procedure or view and do some string manipulation to work this out.

Upvotes: 1

Ray
Ray

Reputation: 21905

By the time the results get back to ado.net, the original source table of the fields are gone - all you have are the field names.

Upvotes: 3

Related Questions