Search code examples
dapper

Dapper... Must declare the scalar variable


I'm starting with Dapper in a C# application (I currently use Entity in most places) and i'm having an issue with a simple query.

I keep getting back "Must declare scalar variable '@ReportId'" but I am declaring it!

db.Execute(@"INSERT INTO cdr_Requests (ReportId, ReportName, StartTime, EndTime, Status, ReportUrl, CreatedAt, UpdatedAt, Timezone, CdrReportRead) VALUES (@ReportId, @ReportName, @StartTime, @EndTime, @Status, @ReportUrl, @CreatedAt, @UpdatedAt, @Timezone, @CdrReportRead)", new { data.id, data.report_name, data.start_time, data.end_time, data.status, data.report_url, data.created_at, data.updated_at, data.timezone, data.cdrreportread });

Here is my class:

    public class cdr_Request
    {
        public int ID { get; set; }

        public string ReportId { get; set; }

        public string ReportName { get; set; }
    }

I'm just having trouble figuring out what is going on!


Solution

  • Ok apparently I had a complete brain fart and was looking at the wrong line. I changed to this and it works:

    db.Execute(@"INSERT INTO cdr_Requests (ReportId, ReportName, StartTime, EndTime, Status, ReportUrl, CreatedAt, UpdatedAt, Timezone, CdrReportRead) 
        VALUES (@ReportId, @ReportName, @StartTime, @EndTime, @Status, @ReportUrl, @CreatedAt, @UpdatedAt, @Timezone, @CdrReportRead)", new {
         ReportId = data.id,
         ReportName = data.report_name,
         StartTime = data.start_time,
         EndTime = data.end_time,
         Status = data.status,
         ReportUrl = data.report_url,
         CreatedAt = data.created_at,
         UpdatedAt = data.updated_at,
         Timezone = data.timezone,
         CdrReportRead = 0
        });