C# 使用OLEDB从文本框插入

C# 使用OLEDB从文本框插入,c#,insert,oracle10g,oledbcommand,C#,Insert,Oracle10g,Oledbcommand,尝试使用OLEDB连接从C#表单插入值时出错 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.Par

尝试使用
OLEDB连接从C#表单插入值时出错

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.OLEDBEException:一个或多个 处理命令时出错。ORA-00936:失踪 表情


我相信你在
值之间缺少了一个空格。在下面的示例中,我为您在字段列表中的
后面添加了一个

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

尝试设置如下参数:-

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();
试试这个:

strSQL=“插入测试表(用户名、密码)”+ “价值(?,)”


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

有人能帮我纠正这个问题吗?我通常使用unicode类型的nvarchar。VarChar依赖于使用的windows代码页。我也建议使用数据适配器。嗨,德里克。谢谢你的帮助。你实际上在哪里编辑代码的?sos,我可以尝试使用该代码。我仍然没有得到结果。显示相同的错误!检查参数,有不同的设置。我避免了OLEDB类型,我使用数据适配器,你应该考虑使用它们,我认为它们更好。@JojoGeorge,它没有给出错误吗?你是这么说的吗?