我正在尝试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();