我試圖執行一個SQL INSERT
命令到使用C#和Visual Studio我的MS Access數據庫2012C#OLEDB 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();
它不會傷害顯示連接字符串也。 – ethorn10
另請參見:我會**首先** **交易,**顯示消息框之前**! –
您有多個Access數據庫的副本嗎?從您的解釋中,很可能您正在更新與正在驗證的數據庫不同的數據庫。按照ethron10的建議,檢查你的連接字符串 –