3

I'm new to using ORACLE with entity framework 5. Trying a simple update statement which won't work and I m getting an error "ORA-00936: missing expression"

Entities context = new Entities();

var Description="UpdateTesting";
var Id = "1";

string UpdateSqlString = @"Update SOURCE Set DESCRIPTION={0} where SOURCEID={1}";

int RowsUpdated = context.Database.ExecuteSqlCommand(UpdateSqlString, Description, Id);

context.SaveChanges();

I have also tried the following but still getting the same error

 Entities context = new Entities();

 var Description = "UpdateTesting";
 var Id = "1";

 var sql = @"Update SOURCE Set DESCRIPTION = @DESCRIPTION WHERE SOURCEID = @Id";

 int RowsUpdated = context.Database.ExecuteSqlCommand(sql, new OracleParameter("DESCRIPTION", Description),
                                                                  new OracleParameter("Id", Id));
 context.SaveChanges();

I have now tried with the following syntax but nothing happens after the ExecuteSqlCommand and the application probably goes in some not-ending loop

var Description="UpdateTesting";
var SOURCEId = "1";

var sql = "Update SOURCE SET DESCRIPTION = :Description WHERE SOURCEID = :SOURCEId";

 int RowsUpdated=context.Database.ExecuteSqlCommand(
            sql,
            new OracleParameter(":Description", Description),
            new OracleParameter(":SOURCEId", SOURCEId));

I can provide SQL Create table script If that would help resolve this.

Any ideas? thanks

4
  • ermm. Tried it but getting this error now "Unable to cast object of type 'System.Data.SqlClient.SqlParameter' to type 'Oracle.DataAccess.Client.OracleParameter'." Commented Jan 20, 2015 at 12:49
  • Getting slightly different error now "Unable to cast object of type 'System.Data.OracleClient.OracleParameter' to type 'Oracle.DataAccess.Client.OracleParameter'" Commented Jan 20, 2015 at 12:55
  • Tried with this namespace now "using Oracle.DataAccess.Client;" but now back to the original error "ORA-00936: missing expression" Commented Jan 20, 2015 at 12:58
  • Sure. Please see updated Commented Jan 20, 2015 at 13:44

3 Answers 3

3

Have you try this? without colon

    var Description="UpdateTesting";
var SOURCEId = "1";

var sql = "Update SOURCE SET DESCRIPTION = :Description WHERE SOURCEID = :SOURCEId";

 int RowsUpdated=context.Database.ExecuteSqlCommand(
            sql,
            new OracleParameter("Description", Description),
            new OracleParameter("SOURCEId"   , SOURCEId));
Sign up to request clarification or add additional context in comments.

Comments

2

Rather than using {0} use :0 instead.

Entities context = new Entities();

var Description="UpdateTesting";
var Id = "1";

string UpdateSqlString = @"Update SOURCE Set DESCRIPTION=:0 where SOURCEID=:1";

int RowsUpdated = context.Database.ExecuteSqlCommand(UpdateSqlString, Description, Id);

context.SaveChanges();

Comments

0

I think that you have to add ' symbol for your update script as the SQL doesn't recognize it as string, like this:

Update SOURCE Set DESCRIPTION='{0}' where SOURCEID={1}

Try to edit other expressions accordingly.

Update:

May be, your problem is in table name (SOURCE may be a reserved keyword, and doesn't be recognized as table name) . Try to wrap it in "", like this:

Update "SOURCE" Set DESCRIPTION='{0}' where SOURCEID={1}

5 Comments

thanks for the answer but I m getting still the same error after putting '
I have tried the following PL SQL in ORACLE query editor and it works Update SOURCE Set DESCRIPTION='SOme Updates Testing' where SOURCEID=1;
In the application, the following line does bring the returns var Rows = context.SOURCEs.ToList(); so there are no issues in the connection or premissions
@Learner Did you try the " quatation?
Yes I did but that does not make any difference string UpdateSqlString = @"Update ""SOURCE"" Set DESCRIPTION={0} where SOURCEID={1}";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.