Panda
Panda

Reputation: 71

Can someone explain what this System.ArgumentException error means?

I have this code:

//check if the user have any previous medical record.
var firstMedical = false;
    var sql="SELECT * FROM Medical WHERE CDSID = @0";
    var myMedical = db.QuerySingle(sql1, myCDSID);
    if (myMedical ==null){

                //if all the medical data is filled in, run sql1 to store all the answer into a database.
                var sql10 = "INSERT INTO Medical (Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15, Q16, Q17, Q18, Q19, Q20, Alcohol, Medication, Details, CDSID) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19, @20, @21, @22, @23)";
                var medquestionnaire = new{q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, alcohol, medication, details, myCDSID};
                db.Execute(sql10, medquestionnaire);

    } else {

                var sql2 = "UPDATE Medical SET Q1=@0, Q2=@1, Q3=@2, Q4=@3, Q5=@4, Q6=@5, Q7=@6, Q8=@7, Q9=@8, Q10=@9, Q11=@10, Q12=@11, Q13=@12, Q14=@13, Q15=@14, Q16=@15, Q17=@16, Q18=@17, Q19=@18, Q20=@19, Alcohol=@20, Medication=@21, Details=@22 WHERE CDSID=@23";
                var updquestionnaire = new{q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, alcohol, medication, details, myCDSID};
                db.Execute(sql2,updquestionnaire); //error is highlighted on this line.

     }

Error is highlighted on db.Execute(sql2,updquestionnaire);.

Error is:

Exception Details: System.ArgumentException
 : No mapping exists from DbType <>f__AnonymousType0`24[System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.Object]
   to a known SqlCeType.

I do not understand what this error means and Webmatrix does not really explain this error clearly at all. How should I interpret that error, and fix it?

Upvotes: 1

Views: 1855

Answers (1)

Frank Boyne
Frank Boyne

Reputation: 4570

Since db.Execute expects an array of objects as the second parameter try changing your new statement to explicitly create an array of objects. Something like this for example...

var updquestionnaire = new object[] {q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, alcohol, medication, details, myCDSID};

Upvotes: 1

Related Questions