2

我正在尝试INSERT使用 C# 和 Visual Studio 2012 在我的 MS Access 数据库中实现 SQL 命令。

但是在那之后,当我打开我的Access数据库时,没有更新,甚至insert可以通过显示成功弹出窗口成功创建命令executeNonQuery()

你能告诉我如何使这个插入到 SQL 命令中工作吗?

这是我的代码

OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = @"INSERT INTO STUDENT(CHI_NAME, ENG_NAME, NICK_NAME, 
                                        BD_YYYY, BD_MM, BD_DD,
                                        HOME_TEL, NO_OF_CHILD, PARENT_EMAIL,
                                        SEC_EMAIL, STUDENT_ADDR, DISTRICT, 
                                        MOTHER_NAME, MOTHER_TEL, MOTHER_OCCU, 
                                        FATHER_NAME, FATHER_TEL, FATHER_OCCU,
                                        E_NAME, E_TEL, E_RELATIONSHIP, REMARKS) 
                    VALUES(@NEW_CHI_NAME, @NEW_EN  G_NAME, @NEW_NICK_NAME, 
                           @NEW_BD_YYYY, @NEW_BD_MM .....);"

cmd.CommandType = CommandType.Text;

cmd.Parameters.AddWithValue("@NEW_CHI_NAME", chi_name);
cmd.Parameters.AddWithValue("@NEW_ENG_NAME", eng_name);
cmd.Parameters.AddWithValue("@NEW_NICK_NAME", nick_name);            
cmd.Parameters.AddWithValue("@NEW_BD_YYYY", bd_year);
cmd.Parameters.AddWithValue("@NEW_BD_MM", bd_month);
....

cmd.Connection = connection;
connection.Open();
cmd.Transaction = connection.BeginTransaction();
int rows= cmd.ExecuteNonQuery();

if(rows > 0)
{
     MessageBox.Show("Insert New Client Success!");
}
else
{
    MessageBox.Show("Insert New Client Failed!"); 
}

cmd.Transaction.Commit();
connection.Dispose();
connection.Close();
4

2 回答 2

2

In Solution Explorer, right click your Access file, choose Properties, and set Copy To Output Directory to Copy if Newer

于 2012-11-19T03:38:15.113 回答
0

转到调试目录,你会发现你的 accdb 文件复制在那里。打开它并验证。

于 2013-01-16T22:09:23.433 回答