2012-04-21 106 views
1

我有这样的代码:有人可以解释这个System.ArgumentException错误的含义吗?

//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 [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] WHERE [email protected]"; 
       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. 

    } 

错误被突出显示在db.Execute(sql2,updquestionnaire);

错误是:

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. 

我不明白这是什么错误意味着和WebMatrix中并没有真正解释这个错误显然在所有。我应该如何解释这个错误并解决它?

+0

您是否尝试过直接在执行线上的所有变量? – Steve 2012-04-21 21:54:00

+0

我想尝试...但我发现错误 – Panda 2012-04-21 22:02:52

回答

1

因为db.Execute需要一个对象数组作为第二个参数,请尝试将您的new语句更改为显式创建一个对象数组。这样的例如...

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}; 
+0

哈哈......也只是意识到这个问题。谢谢,谢谢 – Panda 2012-04-21 22:04:14

相关问题