i enter all the data's in datagridview and save it in the database.when i click load button all data's to be retrived from the database and displayed in to the datagridveiw
i have two buttons called Save And Load(butotn)
Output as follows in data grid veiw.
Date Session GS NR PN
28/1/2013 1 REO
28/1/2013 2 TASCO
28/1/2013 3
28/1/2013 4 AFF
29/1/2013 1
29/1/2013 2 CTF AFF MFA
29/1/2013 3
29/1/2013 4
30/1/2013 1
30/1/2013 2
30/1/2013 3 ECDIS TFC LGTF
30/1/2013 4
31/1/2013 1
31/1/2013 2
31/1/2013 3
31/1/2013 4 REO ERSM ARPA
1/1/2013 1
1/1/2013 2
1/1/2013 3
1/1/2013 4
2/1/2013 1
2/1/2013 2
2/1/2013 3
2/1/2013 4
when i click the save button all the above data's are saved in the database.no problem.this is working fine.
then when i click the Load Button all the data's are to be retrived from the database and displayed in to the data gridview.
Load Button Code as follows;
private void Btn_Load_Click(object sender, EventArgs e)
{
int iCol, jRow, xSession;
try
{
sql = "select distinct [Faculty_code] FROM Tb_SCh_TIme_Table";
OleDbDrFac = GFun.ReadAcessSql(sql);
while (OleDbDrFac.Read())
{
for (iCol = 3; iCol < datagridView.Columns.Count; iCol++)
{
if (datagridView.Columns[iCol].HeaderText == OleDbDrFac[0].ToString().Trim())
{
sql = "select format(Sch_Date,'dd mmm') as Schdate, [Session], [Course] FROM Tb_SCh_TIme_Table ";
sql = sql + "where [Faculty_code] = '" + datagridView.Columns[iCol].HeaderText + "' order by Sch_Date, Session";
OleDrDetail = GFun.ReadAcessSql(sql);
while (OleDrDetail.Read())
{
for (jRow = 0; jRow < datagridView.Rows.Count; jRow++)
{
if (datagridView[0, jRow].Value.ToString() == OleDrDetail[0].ToString().Trim())
{
for (xSession = jRow; xSession <= 3; xSession++)
{
if (datagridView[1, jRow].Value.ToString() == OleDrDetail[1].ToString().Trim())
{
datagridView[iCol, jRow].Value = OleDrDetail[2].ToString().Trim();
}
else
{
jRow++;
}
}
}
}
}
}
}
}
}
catch (Exception ex1)
{
MessageBox.Show(ex1.ToString());
return;
}
}
in run mode screen when i click the load button the error shows as follows;
No data exists for the row/column.
from my above load button code what is the mistake.how can i do? please correct my mistake and help me.