使用Microsoft Access UPDATE命令C#的OleDbConnection和命令不工作 [英] Microsoft Access UPDATE command using C# OleDbConnection and Command NOT working
本文介绍了使用Microsoft Access UPDATE命令C#的OleDbConnection和命令不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是不幸的是,因为更高的力量的Microsoft Access和尝试更新,没有运气的记录。
I'm using Microsoft Access unfortunately because of higher forces and trying to update a record with no luck.
这是在code:
private void UpdateContact(Contact contact)
{
using (OleDbConnection db = new OleDbConnection(_connString))
{
string query = "UPDATE [Contact] SET [FirstName] = @FirstName, [LastName] = @LastName, [MobileNumber] = @MobileNumber WHERE [Id] = @Id";
OleDbCommand cmd = new OleDbCommand(query, db) { CommandType = CommandType.Text };
cmd.Parameters.AddWithValue("@Id", contact.Id);
cmd.Parameters.AddWithValue("@FirstName", contact.FirstName);
cmd.Parameters.AddWithValue("@LastName", contact.LastName);
cmd.Parameters.AddWithValue("@MobileNumber", contact.MobileNumber);
db.Open();
int rowsAffected = cmd.ExecuteNonQuery();
db.Close();
}
}
一切似乎是美好的,没有例外,但没有任何的RowsAffected。它总是返回0。 同时调试和正确的,应该坚持我已经检查过的值。 访问文件中创建与MS Access 2007年,但它的类型是2002-2003。
Everything seems to be fine, no exception but no rowsAffected either. It always returns 0. I have checked the values while debugging and its the correct that should persist. The access file created with MS Access 2007 but its type is of 2002-2003.
知不知道我做错了?
推荐答案
尝试
string query = "UPDATE [Contact] SET [FirstName] = ? [LastName] = ?, [MobileNumber] = ? WHERE [Id] = ?"
添加参数在语句中的顺序,即姓名... ID
Add your parameters in the order of the statement, i.e. firstname...id
这篇关于使用Microsoft Access UPDATE命令C#的OleDbConnection和命令不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文