如何使用连接ms-access的参数化查询更新我的数据 [英] How do I update my data using parameterized queries connecting ms-access
本文介绍了如何使用连接ms-access的参数化查询更新我的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法获取ms-access数据库的确切更新参数化查询。
我尝试过:
I can't get the exact update parameterized query for ms-access database.
What I have tried:
String connectionstring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + txtboxfilename.Text + "';Persist Security Info=False;";
string SqlString = "Update DTR_Table Set Date = ?, Time = ?, Type = ?,
Remarks = ? where Employee = @Employee";
using (OleDbConnection conn = new OleDbConnection(connectionstring))
{
using (OleDbCommand cmd = new OleDbCommand(SqlString, conn))
{
conn.Open();
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Employee", txtboxId.Text);
cmd.Parameters.AddWithValue("Date", DatePicker1.Text);
cmd.Parameters.AddWithValue("Time", TimePicker1.Text);
cmd.Parameters.AddWithValue("Type", combotype.Text);
cmd.Parameters.AddWithValue("Remarks", txtboxremarks.Text);
cmd.ExecuteNonQuery();
conn.Close();
}
}
推荐答案
最后我查了一下,Access没有支持命名参数。您必须按照它们在查询中出现的顺序指定它们。
Last I checked, Access doesn't support named parameters. You have to specify them in the order they appear in the query.
这篇关于如何使用连接ms-access的参数化查询更新我的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文