Sytax error while using ToDate function in Oracle in C#

Last Reply on Aug 05, 2013 02:16 AM By Mudassar

Posted on Aug 05, 2013 02:13 AM

 

I am writing a query to connect oracle db with asp.net, and i have created a webpage and then i kept 6 textboxes, and two buttons for getting input and o/p, on the button click i kept all the thigns, to insert data into db using text boxes. and in textboxes i have to give the date and in oracle db i have created column for those dates, am using to_date function, but i dont know how to write the to_date for continuesly, its says some syntax error. so can you please tell me how to use the to_date function continuesly and next to some appended textboxes, herewith i have written the example query now which i have written and getting error.
 
string oocdate = txtoocaccpteddate.Text;
string filingdate = txtfillingdate.Text;
string fieldautorities = txtfieldwithauth.Text;
string receipt = txtreceiptdate.Text;
string approved = txtapproveddate.Text;
string appvalidfrom = txtapplicationvalidfrom.Text;
string appvalidto = txtapplicationvalidto.Text;

string sql = "insert into tmp (REC_KEY,APPL_NO,EMP_NO,CASE_VISA_TYPE_CODE,CASE_VISA_SUBTYPE_CODE,OOC_ACCEPTED_DATE,FILING_SENT_DATE,FILED_WITH_AUTHORITIES,RECEIPT_DATE,APPROVED_DATE,APPL_VALID_FROM,APPL_VALID_TO)values ('" + txtreckey.Text + "','" + txtrefappno.Text + "','" + txtempid.Text + "','" + txtcasevisatype.Text + "','" + txtcasevisatypecode.Text + "','(TO_DATE('" + oocdate + "','DD-MM-YY HH:MI A.M.'))','(TO_DATE('" + filingdate + "','DD-MM-YY HH:MI A.M.'))','(TO_DATE('" + fieldautorities + "','DD-MM-YY HH:MI A.M.'))','" + txtreceiptno.Text + "','(TO_DATE('" + receipt + "','DD-MM-YY HH:MI A.M.'))','(TO_DATE('" + approved + "','DD-MM-YY HH:MI A.M.'))','(TO_DATE('" + appvalidfrom + "','DD-MM-YY HH:MI A.M.'))','(TO_DATE('" + appvalidto + "','DD-MM-YY HH:MI A.M.'))";

// here i have diclared the textboxes as some var name and i have appending them in to_date functions. here first two columns are varchar type, like rec_key and emp id, case visa type, case visa subtype, these things are varchar and other than this everything is date. i dont knnow the syntax for continuesly using to_date function.
Posted on Aug 05, 2013 02:16 AM

Solving Syntax error in such query is like finding needle in grass bundle.

I would suggest you to stop this incorrect way of writing queries and start using Paramaters

http://www.codeproject.com/Articles/208176/Gotcha-sharp1161-Using-Named-Parameters-with-Oracl

http://weblogs.asp.net/cibrax/archive/2006/09/28/Parameterized-Queries-_2800_Oracle_2C00_-SQLServer_2C00_-OleDb_2900_.aspx

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html