Click here to Skip to main content
Sign Up to vote bad
good
See more: C#
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++)
                        {
                            //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 30-Jan-13 20:18pm
Edited 30-Jan-13 22:31pm

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
Member 8054539 - 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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 6,889
1 Prasad_Kulkarni 3,671
2 OriginalGriff 3,359
3 _Amy 3,312
4 CPallini 2,925


Advertise | Privacy | Mobile
Web03 | 2.6.130617.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid