Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;

C#
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++)
                        {
                            //date
                            if (datagridView[0, jRow].Value.ToString() == OleDrDetail[0].ToString().Trim())
                            {
                                //session
                                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.
Posted
Updated 30-Jan-13 22:31pm
v2
Comments
boogac 31-Jan-13 2:47am    
try degub mode.writing the lines which error(s) occur will be helpful for who try to help you
[no name] 31-Jan-13 3:44am    
No data exists for the row/column.
Richard MacCutchan 31-Jan-13 4:33am    
Have you checked that the data is actually saved in your database?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900