C# x的最佳重载方法匹配有一些无效参数(另外两个错误)
当我尝试使用Linq to SQL向数据库添加保存内容的函数时,收到三个错误 匹配的最佳重载方法 'System.Data.Entity.DbSet.Add(Egen_projekt.Personer)' 有一些无效的参数 参数1:无法从“Egen_projekt.Person”转换为 “Egen_项目人员” 方法“Add”的重载不包含2个参数 发送功能:C# x的最佳重载方法匹配有一些无效参数(另外两个错误),c#,asp.net,linq,C#,Asp.net,Linq,当我尝试使用Linq to SQL向数据库添加保存内容的函数时,收到三个错误 匹配的最佳重载方法 'System.Data.Entity.DbSet.Add(Egen_projekt.Personer)' 有一些无效的参数 参数1:无法从“Egen_projekt.Person”转换为 “Egen_项目人员” 方法“Add”的重载不包含2个参数 发送功能: protected void Button1_Click(object sender, EventArgs e) {
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();
}
网页形式:
<form method="post">
Name: <asp:TextBox runat="server" ID="txt1"></asp:TextBox>
<br />
Twitter link: <asp:TextBox runat="server" ID="txt2"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Save" onclick="Button1_Click" /></form>
姓名:
我遗漏了什么?方法db.Personer.Add()
希望您传入类型为Personer
的对象,但您传入的是两个字符串。您需要创建一个新的Personer
对象,设置您想要的任何属性,然后将其传递到db.Personer.Add()
关于错误消息有什么不清楚的地方?为什么会被否决?你可能不喜欢他的问题,但我的回答是正确的,被接受了