在Acceess2010中插入数据时遇到问题 [英] Geting problem to insert data in Acceess2010

查看:70
本文介绍了在Acceess2010中插入数据时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Microsoft OfficeAccess2010中插入数据.
当我插入数据时,它显示错误.
错误是-----"Insert Into语句中的语法错误"

我的要求是...

I want to insert data in Microsoft OfficeAccess2010.
When I insert data it shows error.
Error is----- "Syntax Error in Insert Into statement"

my codding is....

con = new OleDbConnection();
            ConnectionClass cc = new ConnectionClass();
            con.ConnectionString = cc.GetConnection();

            //DataSet1 ds = new DataSet1();
            DataSet ds1 = new DataSet();
            da1 = new OleDbDataAdapter("Select * from Sam", con);
            OleDbCommandBuilder builder = new OleDbCommandBuilder(da1);
            con.Open();
            da1.Fill(ds1, "Sam");
            DataRow dr = ds1.Tables["Sam"].NewRow();


            int r1 = dataGridView1.Rows.Count;
            for (int r = 0; r < r1; r++)
            {
                dr[0] = txtCompanyName.Text;
                dr[1] = txtAddress.Text;
                dr[2] = txtFrom.Text;
                dr[3] = txtTo.Text;
                dr[4] = dataGridView1.Rows[r].Cells[0].Value;
                dr[5] = dataGridView1.Rows[r].Cells[1].Value;
                dr[6] = dataGridView1.Rows[r].Cells[2].Value;
                dr[7] = dataGridView1.Rows[r].Cells[3].Value;
                dr[8] = dataGridView1.Rows[r].Cells[4].Value;
                dr[9] = dataGridView1.Rows[r].Cells[5].Value;
               
            }
            dr[10] = dataGridView1.Rows[r1-1].Cells[5].Value;
            dr[11] = txtServicTex.Text;
            dr[12] = txtHigherEducation.Text;
            dr[13] = txteducationCess.Text;
            try
            {
                ds1.Tables["Sam"].Rows.Add(dr);
                da1.Update(ds1, "Sam");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }

推荐答案

您必须设置UpdateCommand属性:MSDN DataAdapter.Update方法 [
You have to set the UpdateCommand property: MSDN DataAdapter.Update Method[^]


这篇关于在Acceess2010中插入数据时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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