Data is not inserting oracle table using ODP.NET through asp.net
I am inserting record in Oracle table using ODP.NET Oracle.DataAccess.Client throug Asp.net c#. The oracle table is tblGroup and GROUPNAME varchar2,GROUPDETAILS varchar2 is column name but data is not inserting.I am using following code
public void insertRecord(string StudentgroupName, string groupDetails)
{
using (OracleConnection con = GetConnection())
{
OracleCommand cmd = new OracleCommand();
cmd.Connection = con; //assigning connection to command
cmd.CommandType = CommandType.Text; //representing type of command
cmd.CommandText = "INSERT INTO tblGroup (GROUPNAME,GROUPDETAILS) values(@GROUPNAME,@GROUPDETAILS)";
//adding parameters with value
cmd.Parameters.Add("@GROUPNAME", StudentgroupName);
cmd.Parameters.Add("@GROUPDETAILS", groupDetails);
con.Open(); //opening connection
cmd.ExecuteNonQuery();
}
}
and got following error
Oracle.DataAccess.Client.OracleException ORA-00936: missing expression at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck) at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck) at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery() at SchoolsManagementSystem.DAL.insertRecord(String StudentgroupName, String groupDetails) in d:c#SchoolsManagementSystemSchoolsManagementSystemApp_CodeDAL.cs:line 85 at SchoolsManagementSystem.Group.btnSubmit_Click(Object sender, EventArgs e) in d:c#SchoolsManagementSystemSchoolsManagementSystemGroup.aspx.cs:line 26
Guide me How can I solve my problem
In your SQL statement, use a colon prefix to indicate bind parameter, not @:
INSERT INTO t (COL1) values(:param1)
Using the @ symbol works ok for SQL Server, for not for Oracle.
Also, your bind statement needs to just use the name "GROUPNAME", no prefix character @ or : needed in the parameters.Add() call.
Like so:
cmd.CommandText =
"INSERT INTO tblGroup (GROUPNAME,GROUPDETAILS) values(:GROUPNAME, :GROUPDETAILS)";
cmd.Parameters.Add("GROUPNAME", StudentgroupName);
cmd.Parameters.Add("GROUPDETAILS", groupDetails);
链接地址: http://www.djcxy.com/p/67192.html