Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have following code to show data in gridview:
private void panel4_Click(object sender, EventArgs e)
        {

            try 
            {
                


                OleDbDataAdapter adpt = new OleDbDataAdapter("select Stu_name as 'Name' ,Stu_class as 'Class',Stu_roll as 'Roll Number',Stu_section as 'Section',Attendence from EnrollStud where Stu_class='" + comboBox3.SelectedItem + "' and Stu_section='" + comboBox4.SelectedItem + "'", conn);
                conn.Open();

                OleDbCommandBuilder cdb = new OleDbCommandBuilder(adpt);
                
                adpt.Fill(ds);
                adpt.Fill(dt);
                ds.Tables[0];
                a = dt.Rows.Count;
                
                if (dt.Rows.Count.Equals(0))
                {
                    MessageBox.Show("Sorry!Please Select Correct Class and section");

                }
                else
                {
                    dataGridView1.DataSource =dt;
}
                conn.Close();
}

on save button click i want to update changes of gridview into acess database

private void button1_Click(object sender, EventArgs e)
        {

        try
            {
                if (dataGridView1.Rows.Count.Equals(0))
                {
                    MessageBox.Show("select some data!!","message",MessageBoxButtons.OK,MessageBoxIcon.Stop);

                }
                else
                {
                    adpt.Update(dt);

                    MessageBox.Show("Record is updated", "message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            
            }
            

        }


I am using acess2003 as database
Posted
Comments
Clifford Nelson 11-Apr-12 4:29am    
You may wont to include what your problem is.

1 solution

Please see this Code Project article, in which a general purpose class is given to read data from Access Database and to save data to the Database.
General purpose class to fill DataTable(s) from DataBase and to save DataTable(s) to DataBase using reflection[^]
I think it may be helpful to you.
 
Share this answer
 

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