3
Answers

object ref while passing SqlDataReader into DataSet in c#

Bineesh  VP

Bineesh VP

7y
202
1
Hi Sir,
 
An error is coming while I passing SqlDataReader into DataSet.
 
Kindly go through the code given below and suggest a solution.
  1. sqlRdr = sqlcmd.ExecuteReader();  
  2. while (sqlRdr.Read())  
  3. {  
  4. dgvFeedBack.DataSource = sqlRdr;  
  5. }  
  6. if (!sqlRdr.HasRows)  
  7. {  
  8. RadMessageBox.SetThemeName("Windows7");  
  9. RadMessageBox.Show("\nNo Records found between " + dtFromFeedback.Text + " and " + dtToFeedback.Text, "CollectPlus - Du Feedback", MessageBoxButtons.OK, RadMessageIcon.Exclamation);  
  10. dgvFeedBack.DataSource = null;  
  11. dgvFeedBack.Rows.Clear();  
  12. btnExportData.Enabled = false;  
  13. }  
  14. lblTotalNoOfActions.Text = dgvFeedBack.Rows.Count.ToString();  
  15. DsAllFeedback.Tables.Add().Load(sqlRdr);  
  16. sqlCon.Close();
Answers (3)