1

我在尝试使用OLEDB Connection.

strSQL = "INSERT INTO test_table (username,password) " +
"VALUES (@user,@pass)";

objCmd = new OleDbCommand(strSQL, objConnection);
objCmd.Parameters.Add("@user", OleDbType.VarChar, 255).Value =TextBox1.Text.Trim();

objCmd.Parameters.Add("@pass", OleDbType.VarChar, 255).Value= TextBox2.Text.Trim();

// execute the command
objCmd.ExecuteNonQuery();

objConnection.Close();
Label1.Text = "Command run";    

错误是

异常详细信息:System.Data.OleDb.OleDbException:处理命令期间发生一个或多个错误。ORA-00936: 缺少表达式

4

3 回答 3

2

我相信你错过了VALUES朋友之间的空间。)在下面的示例中,我在字段列表中为您添加了一个。

strSQL = "INSERT INTO test_table (username,password) " +
"VALUES (@user,@pass)";
于 2012-11-05T12:14:16.733 回答
1

尝试像这样设置参数:-

objConnection = new OleDbConnection(strConnection);
objConnection.ConnectionString = strConnection;

objConnection.Open();



// set the SQL string
strSQL = "INSERT INTO test_table (username,password) " +
"VALUES (@user,@pass)";
// Create the Command and set its properties
objCmd = new OleDbCommand(strSQL, objConnection);

objCmd.Parameters.AddWithValue("@user", TextBox1.Text);

objCmd.Parameters.AddWithValue("@pass", TextBox2.Text);

// execute the command
objCmd.ExecuteNonQuery();

objConnection.Close();
于 2012-11-05T12:15:26.923 回答
0

尝试这个 :

strSQL = "INSERT INTO test_table (username,password)" + "VALUES (?,?)";

使用 OleDb 您需要输入“?” 而不是@param 作为参数

于 2015-06-22T08:27:30.003 回答