Harish Batchu

Harish Batchu

  • NA
  • 255
  • 70.2k

error- System.InvalidOperationException: 'Invalid attempt to

Oct 11 2018 2:19 PM
error-
System.InvalidOperationException: 'Invalid attempt to read when no data is present.'
please the fix issue
 
 
SqlCommand cmd1 = new SqlCommand("ChartData",con);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.Add("@Uuniq",SqlDbType.VarChar).Value = Username;
SqlDataReader dr = cmd1.ExecuteReader();
var datamodallist = new ObservableCollection<DatachartModal>();
if (dr.HasRows)
{
object viewdt = dr.Read();
object viewedt = dr.Read();
var datachartModal = new DatachartModal
{
Type = dr.GetString(0),
Amount = dr.GetString(1)
};
datamodallist.Add(datachartModal);
}
dr.Close();
 
 
class DatachartModal
{
public string Type { get; set; }
public string Amount { get; set; }
}
 
 
 

Answers (2)