Hello,
I am using a sqldatareader to get back a whole set of data.
The columns are id, data_id and data_desc
for example, the collection is
id   data_id   data_desc
0    100       this is name for id 0
0    101       this is address for id 0
0    102       this is gender for id 0
1    100       this is name for id 1
1    101       this is address for id 1
1    102       this is gender for id 1
2    100       this is name for id 2
2    101       this is address for id 2
2    102       this is gender for id 2
3    100       this is name for id 3
3    101       this is address for id 3
3    102       this is gender for id 3
I want to be able to go thru' this list and break up for each id and create a txt file. So, i will have four text files.
txt0.txt will contain
100, this is name for id 0
101, this is address for id 0
102, this is gender for id 0
I would like to know, how do i use a dataview to break up the sqldatareader so i can then repeat the loop for each id and generate the text file.
I don't have a problem generating the text file.
Please let me know, how should i go about it.
Thanks a bunch,
-Sean
If you are just looking to loop thru a SqlDataReader. Try this.
SqlCommand cmd = new SqlCommand("<Your query here>", con); 
cmd.Connection.Open();
SqlDataReader dtrText = cmd.ExecuteReaderCommandBehavior.CloseConnection);
while(dtrText.Read())  
 { 
   //Write to text file here.
 } 
dtrText.Close();
con.Close();
Hope this helps.
 
No comments:
Post a Comment