user1081326
user1081326

Reputation: 425

ORA-01756: quoted string not properly terminated

I have this error, and i roughly know where it is, but do not know how to correct it.

Error Message:

ORA-01756: quoted string not properly terminated

"INSERT INTO Patients1 VALUES ('System.Windows.Forms.TextBox, Text: 0001' ,'M', '25-AUG-1991' , 'Aaron' , 'R' , 'O'Neill' , '6ft' , '11st' , '0664534334' , '0876543213' , '0001' , 'PAT', 'has a heart condition')"

and here is my code:

string sql = "INSERT INTO Patients1 VALUES (" + TxtPatientId +"' ,'" + TxtGender.Text + "', '" + TxtDob.Text + "' , '" + TxtFName.Text + "' , '" +
                TxtMName.Text + "' , '" + TxtLName.Text + "' , '" + TxtHeight.Text + "' , '" + TxtWeight.Text + "' , '" + TxtHomePh.Text + 
                "' , '" + TxtMobPhone.Text + "' , '"  + TxtDocId.Text + "' , '" + TxtViewType.Text + "', '" +
                TxtPDetails.Text + "')";

I think my error is coming from the very 1st input (PatientId).

my database table looks like this:

CREATE TABLE Patient1
   (Patient_id NUMBER(6)    NOT NULL,
    GENDER VARCHAR2(1) NOT NULL, 
    DATE_OF_BIRTH DATE,
    PATIENT_FIRST_NAME VARCHAR2(9)  NOT NULL,
    PATIENT_MIDDLE_INITIAL VARCHAR2(1),
    PATIENT_SURNAME VARCHAR2(9) NOT NULL,
    HEIGHT NUMBER(3,2),
    WEIGHT NUMBER(5,2),
    HOME_PHONE NUMBER(10)   NOT NULL,
    MOBILE_PHONE NUMBER(10) NOT NULL,
    DOCTOR_ID NUMBER(6) NOT NULL,
    VIEWTYPE VARCHAR2(3) DEFAULT 'PAT',
    OTHER_PATIENT_DETAILS VARCHAR2(50),
    CONSTRAINT patients_pk PRIMARY KEY(Patient_id));

Any help here would be appreciated

Upvotes: 1

Views: 24809

Answers (2)

Michael Berkowski
Michael Berkowski

Reputation: 270627

Looks like you are not accessing the .text property of the input. Additionally, you have not opened a single quote for the first item in the VALUES list:

VALUES (" + TxtPatientId +"'

Should be:

VALUES ('" + TxtPatientId.text +"'

You have not escaped single quotes in your other parameters. O'Neill has a quote which breaks the rest of the statement.

See @vc 74's answer for information on using bound parameters instead of concatenated strings to build your query.

Upvotes: 6

vc 74
vc 74

Reputation: 38179

You need to escape the single quote in O'Neill by doubling it or use bind parameters instead of hardcoded values in your query

Upvotes: 5

Related Questions