Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How To Transfer the all Recored in Datatable From DataReader

when i use
datatable.load(datareader);

the first record is missing
means
my query is giving 4 record dataTable Has only 3 record the first record is missing;
Posted
Comments
Timberbird 28-Jun-11 8:30am    
Could you provide some code to show how you create DataReader?

1 solution

Without seeing your code, I can only make an educated guess:
Are you doing this:
SqlDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
if (reader.Read())
    {
    dt.Load(reader);
    }
Because, if you are, that's your problem: the Read method removes one of the records from the list...


"this code is run succesfully but top record is missing"


Yes - the Read() method call removes the first record. Don't call Read. Instead, check reader.HasRows[^]


"but any option to send data into datatable from datareader"


Try:
SqlDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
if (reader.HasRows)
    {
    dt.Load(reader);
    }
 
Share this answer
 
v3
Comments
Chitranjan Pd Asthana 29-Jun-11 1:39am    
this code is run succesfully but top record is missing
OriginalGriff 29-Jun-11 3:05am    
Answer updated
Chitranjan Pd Asthana 29-Jun-11 4:07am    
but any option to send data into datatable from datareader
OriginalGriff 29-Jun-11 4:13am    
I'm not totally sure what you are asking here, but... answer updated
Chitranjan Pd Asthana 30-Jun-11 5:31am    
my query is return a group of records
its have present in datareader
but in datatable have lessthan one record present.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900