插入ms Access数据库 [英] insert into ms access database

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

问题描述

我使用以下代码将一个记录从一个数据库插入另一个数据库,但是它不起作用.我在MS-ACCESS 2007中尝试了该查询,该查询工作正常,但从C#代码以编程方式调用时却无法正常工作?

I use the following code to insert a record from one database to another but it doesn't work. I tried the query in MS-ACCESS 2007 and it works fine but it doesn't work when called programmatically from my C# code?

string query_insert = "INSERT INTO Questionnaires_Table(BranchName,Factor,Region,Branch_ID,Current_Date,No_Employees) "
+ "SELECT BranchName,Factor,Region,Branch_ID,Current_Date,No_Employees "
+ "FROM Questionnaires_Table IN '" + dialog.FileName + "' Where Branch_ID = " + textBox1.Text ;

dbConnDest.Open();

OleDbDataAdapter dAdapter = new OleDbDataAdapter();
OleDbCommand cmd_insert = new OleDbCommand(query_insert, dbConnDest);

dAdapter.InsertCommand = cmd_insert;

textBox2.Text = query_insert.ToString();

dbConnDest.Close();

当我在ms Access中获取query_insert的内容时,它工作正常.

When I take the the content of query_insert in ms access, it works fine.

推荐答案

我认为您需要使用

cmd_insert.executeNonQuery()

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

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