Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code,

C#
public void AddNDADetails(string id)
       {
           try
           {
               con = db.CreateConnection();
               con.Open();

               string query = string.Format("INSERT INTO NDAInformation (NDAID,RegNumber,DateCreate,RefName,ReqServ,ServDetails) VALUES (:ndaID,:regnumber,TO_DATE(:date,'DDMMYYYY'),:refname,:regserv,:servdetails)");
               //string query = string.Format("INSERT INTO NDAInformation (NDAid,RegNumber,DateCreate,RefName,ReqServ,ServDetails) VALUES ('{0}', '{1}',TO_DATE('{2}','DDMMYYYY'), '{3}','{4}','{5}')", id, om.RegNumber, om.Date, om.ComRef, om.ComService, string.Join(",", om.ReqServiceDetails));
               cmd = db.GetSqlStringCommand(query);
               cmd = con.CreateCommand();
               cmd.CommandText = query;

               db.AddInParameter(cmd, "ndaID", DbType.String, id);
               db.AddInParameter(cmd, "regnumber", DbType.String, om.RegNumber);
               db.AddInParameter(cmd, "date", DbType.Date, om.Date);
               db.AddInParameter(cmd, "refname", DbType.String, om.ComRef);
               db.AddInParameter(cmd, "regserv", DbType.String, om.ComService);
               db.AddInParameter(cmd, "servdetails", DbType.String, string.Join(",", om.ReqServiceDetails));
               db.ExecuteNonQuery(cmd);

           }

           catch (Exception ex)
           {
               throw ex;
           }
       }
Posted

1 solution

date is a reserved word that can't be used as a name for a bind variable.
Change it to for example :DateCreate.
 
Share this answer
 
v2
Comments
Jörgen Andersson 24-Mar-15 15:49pm    
Oh, and since you're using a parameter with the type Date you don't need the To_Date in the DML

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900