I have a remote sql connection in C # that needs to execute a query and save its results on the user's local hard drive. There is a fairly large amount of data that this thing can return, so you need to think about an effective way to store it. I read before I first put the whole result in memory, and then wrote that this is not a good idea, so if someone could help, it would be great!
I am currently storing sql result data in a DataTable, although I think it is better to do something in while(myReader.Read(){...} The following is the code that gets the results:
DataTable t = new DataTable(); string myQuery = QueryLoader.ReadQueryFromFileWithBdateEdate(@"Resources\qrs\qryssysblo.q", newdate, newdate); using (SqlDataAdapter a = new SqlDataAdapter(myQuery, sqlconn.myConnection)) { a.Fill(t); } var result = string.Empty; for(int i = 0; i < t.Rows.Count; i++) { for (int j = 0; j < t.Columns.Count; j++) { result += t.Rows[i][j] + ","; } result += "\r\n"; }
So now I have this huge line of result. And I have data. Should there be a much better way to do this?
Thanks.
source share