Hi experts...I am retrieving data from db and displaying in textboxes using dataadapter and dataset...but m getting error like There is no row at position 2...plz help me how i have to handle this...thanks
SqlCommand command = new SqlCommand("CTT_Shift_Closing_Fetch", con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@i_Intime", SqlDbType.VarChar).Value = txtInTime.Text.Trim();
command.Parameters.Add("@i_OutTime ", SqlDbType.VarChar).Value = txtOutTime.Text.Trim();
SqlDataAdapter da = new SqlDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds, "Shift");
int i = 1;
if (ds.Tables[0].Rows.Count > 0)
{
for (int j = 0; j <= ds.Tables[0].Rows.Count; j++)
{
if (i == 1)
{
txtStaffName1.Text = ds.Tables["Shift"].Rows[j]["StaffAssigned"].ToString();
txtPumpProduct1.Text = ds.Tables["Shift"].Rows[j]["Pump_ProductId"].ToString();
txtPump1.Text = ds.Tables["Shift"].Rows[j]["PumpName"].ToString();
txtPump1_Opening.Text = ds.Tables["Shift"].Rows[j]["Pump_Opening_Reading"].ToString();
lblShiftId.Text = ds.Tables["Shift"].Rows[j]["ShiftId"].ToString();
}
else if (i == 2)
{
Text_Show2();
txtStaffName2.Text = ds.Tables["Shift"].Rows[j]["StaffAssigned"].ToString();
txtPumpProduct2.Text = ds.Tables["Shift"].Rows[j]["Pump_ProductId"].ToString();
txtPump2.Text = ds.Tables["Shift"].Rows[j]["PumpName"].ToString();
txtPump2_Opening.Text = ds.Tables["Shift"].Rows[j]["Pump_Opening_Reading"].ToString();
lblShiftId2.Text = ds.Tables["Shift"].Rows[j]["ShiftId"].ToString();
}
else if (i == 3)
{
txtStaffName3.Text = ds.Tables["Shift"].Rows[j]["StaffAssigned"].ToString();
txtPumpProduct3.Text = ds.Tables["Shift"].Rows[j]["Pump_ProductId"].ToString();
txtPump3.Text = ds.Tables["Shift"].Rows[j]["PumpName"].ToString();
txtPump3_Opening.Text = ds.Tables["Shift"].Rows[j]["Pump_Opening_Reading"].ToString();
lblShiftId3.Text = ds.Tables["Shift"].Rows[j]["ShiftId"].ToString();
}
else if (i == 4)
{
txtStaffName4.Text = ds.Tables["Shift"].Rows[j]["StaffAssigned"].ToString();
txtPumpProduct4.Text = ds.Tables["Shift"].Rows[j]["Pump_ProductId"].ToString();
txtPump4.Text = ds.Tables["Shift"].Rows[j]["PumpName"].ToString();
txtPump4_Opening.Text = ds.Tables["Shift"].Rows[j]["Pump_Opening_Reading"].ToString();
lblShiftId4.Text = ds.Tables["Shift"].Rows[j]["ShiftId"].ToString();
}
else if (i == 5)
{
txtStaffName5.Text = ds.Tables["Shift"].Rows[j]["StaffAssigned"].ToString();
txtPumpProduct5.Text = ds.Tables["Shift"].Rows[j]["Pump_ProductId"].ToString();
txtPump5.Text = ds.Tables["Shift"].Rows[j]["PumpName"].ToString();
txtPump5_Opening.Text = ds.Tables["Shift"].Rows[j]["Pump_Opening_Reading"].ToString();
lblShiftId5.Text = ds.Tables["Shift"].Rows[j]["ShiftId"].ToString();
}
else if (i == 6)
{
txtStaffName6.Text = ds.Tables["Shift"].Rows[j]["StaffAssigned"].ToString();
txtPumpProduct6.Text = ds.Tables["Shift"].Rows[j]["Pump_ProductId"].ToString();
txtPump6.Text = ds.Tables["Shift"].Rows[j]["PumpName"].ToString();
txtPump6_Opening.Text = ds.Tables["Shift"].Rows[j]["Pump_Opening_Reading"].ToString();
lblShiftId6.Text = ds.Tables["Shift"].Rows[j]["ShiftId"].ToString();
}
else if (i == 7)
{
txtStaffName7.Text = ds.Tables["Shift"].Rows[j]["StaffAssigned"].ToString();
txtPumpProduct7.Text = ds.Tables["Shift"].Rows[j]["Pump_ProductId"].ToString();
txtPump7.Text = ds.Tables["Shift"].Rows[j]["PumpName"].ToString();
txtPump7_Opening.Text = ds.Tables["Shift"].Rows[j]["Pump_Opening_Reading"].ToString();
lblShiftId7.Text = ds.Tables["Shift"].Rows[j]["ShiftId"].ToString();
}
else if (i == 8)
{
txtStaffName8.Text = ds.Tables["Shift"].Rows[j]["StaffAssigned"].ToString();
txtPumpProduct8.Text = ds.Tables["Shift"].Rows[j]["Pump_ProductId"].ToString();
txtPump8.Text = ds.Tables["Shift"].Rows[j]["PumpName"].ToString();
txtPump8_Opening.Text = ds.Tables["Shift"].Rows[j]["Pump_Opening_Reading"].ToString();
lblShiftId8.Text = ds.Tables["Shift"].Rows[j]["ShiftId"].ToString();
}
else if (i == 9)
{
txtStaffName9.Text = ds.Tables["Shift"].Rows[j]["StaffAssigned"].ToString();
txtPumpProduct9.Text = ds.Tables["Shift"].Rows[j]["Pump_ProductId"].ToString();
txtPump9.Text = ds.Tables["Shift"].Rows[j]["PumpName"].ToString();
txtPump9_Opening.Text = ds.Tables["Shift"].Rows[j]["Pump_Opening_Reading"].ToString();
lblShiftId9.Text = ds.Tables["Shift"].Rows[j]["ShiftId"].ToString();
}
else if (i == 10)
{
txtStaffName10.Text = ds.Tables["Shift"].Rows[j]["StaffAssigned"].ToString();
txtPumpProduct10.Text = ds.Tables["Shift"].Rows[j]["Pump_ProductId"].ToString();
txtPump10.Text = ds.Tables["Shift"].Rows[j]["PumpName"].ToString();
txtPump10_Opening.Text = ds.Tables["Shift"].Rows[j]["Pump_Opening_Reading"].ToString();
lblShiftId10.Text = ds.Tables["Shift"].Rows[j]["ShiftId"].ToString();
}
i = i + 1;
}
}
}