2016-05-30 56 views
-4

當我試圖添加一個函數來保存某些東西到我的數據庫,使用Linq to SQL時,接收到三個錯誤。x的最佳重載方法匹配有一些無效參數(兩個以上的錯誤)

爲 'System.Data.Entity.DbSet.Add(Egen_projekt.Personer)' 最佳重載的方法匹配具有一些無效參數

參數1:無法從 'Egen_projekt.Person' 轉換爲 'Egen_projekt.Personer'

無重載方法 '添加' 需要兩個參數

發送函數:

protected void Button1_Click(object sender, EventArgs e) 
    { 
     string one = txt1.Text; 
     string two = txt2.Text; 
     db.Personer.Add(txt1.Text, txt2.Text); 
     db.SaveChanges(); 

} 

Web表單:

<form method="post"> 
Name: &nbsp;<asp:TextBox runat="server" ID="txt1"></asp:TextBox> 
<br /> 
Twitter link: &nbsp;<asp:TextBox runat="server" ID="txt2"></asp:TextBox> 
<asp:Button ID="Button1" runat="server" Text="Save" onclick="Button1_Click" /></form> 

實體框架模型:

http://i.imgur.com/qrnOSpd.png

什麼我錯過了嗎?

+4

什麼是不明確的錯誤消息? – Sybren

回答

0

方法db.Personer.Add()期望您傳入Personer類型的對象,但是您傳入兩個字符串。您需要創建一個新的Personer對象,設置所需的任何屬性,然後將其傳遞給db.Personer.Add()

+0

爲什麼這會降低投票率?你可能不喜歡他的問題,但我的回答是正確的,並被接受 –

相關問題