Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 21:18pm
Edited 30-Jan-13 23:31pm
(no name)399.5K
v2
Comments
boogac at 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 at 31-Jan-13 3:44am
   
No data exists for the row/column.
Richard MacCutchan at 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
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,327
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,920


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100