|
using (OleDbConnection oleDb = new OleDbConnection(ConfigurationManager.ConnectionStrings["connStr"].ConnectionString))
{
oleDb.Open();
string sql = "INSERT INTO UserInfo (UserName, UserPassword,Name) VALUES (@username,@UserPassword,@Name);";
OleDbCommand cmd = new OleDbCommand(sql, oleDb);
OleDbParameter[] parameters =
{
new OleDbParameter("@username", "hy001"),
new OleDbParameter("@UserPassword", "*******"),
new OleDbParameter("@Name", "hushao")
};
cmd.Parameters.AddRange(parameters);
object cws = cmd.ExecuteNonQuery();
Console.WriteLine(cws.ToString());
}
这是我的代码
数据库很简单,就是UserName,UserPassword,Name 三个文本
用字符串拼接的方式能成功
用parameter多参数就报错
System.AccessViolationException
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=<无法计算异常源>
StackTrace:
<无法计算异常堆栈跟踪>
但是单参数运行就能成功
|
|
|