Question

I'm getting an error while I'm trying to insert a value from a C# form using 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";    

Error is

Exception Details: System.Data.OleDb.OleDbException: One or more errors occurred during processing of command. ORA-00936: missing expression

Was it helpful?

Solution

I believe you're missing a space between VALUES friend. I added one after the ) in the fields list for you in the below example.

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

OTHER TIPS

Try setting up Parameters like this :-

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();

try this :

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

using OleDb you need to put "?" rather than @param for parameter

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top