Hi There

I am new to c#. I am using SqlDataReader to read database records(using c#).I have found lots of way to do it,but for performance i have found that ordinal reading is fast. Now I want to read a guid field ,as we know that with ordinal reading we can do this in two way
1)reader.GetGuid(0)
2) (Guid)reader[0]

but I don't know which will be faster...

Test it and find out. The different will be negligible either way so I would concern myself with "which code base is easier to maintain". If you're looking for blazing-fast performance then .NET is not the way to go.

Also using the SqlDataReader like that could be considered slower because from the looks of it you're requesting records one-by-one. Sometimes it is best to ask for all of the data and cache it memory, do your processing, then free the memory. The network layer of retrieving data has a fixed amount of overhead to initiate a request for any amount of records, ie: send command to get data, wait for response.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.