更新Acess2003数据库 [英] update Acess2003 database

查看:78
本文介绍了更新Acess2003数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码在gridview中显示数据:

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

推荐答案

请参阅此代码项目文章,其中提供了一个通用类,用于从Access数据库读取数据并将数据保存到数据库. br/> 用于从DataBase和使用反射将DataTable保存到数据库中 [
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.


这篇关于更新Acess2003数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆