kosh
kosh

Reputation: 561

SqlDataReader.GetGuid with column name c#?

Is there a way to get a column by name and retain the SQL type information returned by SqlDataReader?

I only see .GetGuid(int column)?

Upvotes: 4

Views: 4287

Answers (2)

Bradley Smith
Bradley Smith

Reputation: 13601

You could always just cast the result of the SqlDataReader's indexer:

Guid myGuid = (Guid)myDataReader["myColumnName"];

Upvotes: 3

marc_s
marc_s

Reputation: 754368

There is no separate method to get a GUID (or any of the other types) by column name directly.

What you need to do is this:

Guid someguid = dr.GetGuid(yourDataReader.GetOrdinal("your-col-name"));

Upvotes: 4

Related Questions