Unable insert records to a Date fields

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Cloud Applications
Post Reply
rcardoso
Posts: 6
Joined: Thu 31 Jul 2014 23:49

Unable insert records to a Date fields

Post by rcardoso » Fri 01 Aug 2014 16:07

I am having issues inserting a record to a date field in Salesforce
This is the error I get: "You have an error in your SQL syntax at line 5, column 15: ')' expected
I tried with out the time option but it gives me an "Unsupported expression type Binary

See Example


insert into Opportunity (AccountId,Name,StageName,CloseDate,Type,OwnerId,Is_Coverage_currently_in_place) values
( '00130000011CQb5AAG',
'Prospect test',
'Prospect',
7/31/2014 12:00:00 AM,
'New Business',
'00530000007lHuBAAU',
'No' )
RETURNING Id

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Unable insert records to a Date fields

Post by Shalex » Mon 04 Aug 2014 13:14

1. You should quote with a single quote (') the date specified in the query text.
2. The format of the date depends on a default format for dates of your Visual Studio's language. For example: the value should be '2014-07-31 12:00:00' in my test code.
3. You can also use parameters when employing date columns in the query:

Code: Select all

    SalesforceCommand cmd = conn.CreateCommand();
    cmd.CommandText = @"insert into Opportunity (AccountId,Name,StageName,CloseDate, ...) values
    ( '00130000011CQb5AAG', 
    'Prospect test', 
    'Prospect', 
    :myparam, ...";
    cmd.Parameters.Add("myparam", SalesforceType.DateTime).Value =  new DateTime(2013, 07, 01, 12, 0, 0);
    cmd.ExecuteNonQuery();

rcardoso
Posts: 6
Joined: Thu 31 Jul 2014 23:49

Re: Unable insert records to a Date fields

Post by rcardoso » Mon 04 Aug 2014 16:52

Thank you

Post Reply