【问题标题】:required parameter wrror in c#c#中的必填参数错误
【发布时间】:2019-09-23 10:59:30
【问题描述】:

我在 c# windows.form 中创建一个表单,然后创建数据库(MySql)。 然后我尝试使用 linq 将我的表单信息保存到数据库中,一切正常,但它是我不理解的字符串错误? 有我的代码:

var db = new class1DataContext();
db.userssave(txtusername.Text, txtfirstname.Text, txtlastname.Text, txtgender.Text, mobile, txtcountry.Text, txtemail.Text, txtrealestate.Text, Convert.ToInt16(level), txtsocialid.Text, txtdate.Value, txtpassword.Text, txtaddress.Text);

还有错误:

Severity    Code    Description Project File    Line    Suppression State
Error   CS7036  There is no argument given that corresponds to the required formal parameter 'address' of 'class1DataContext.userssave(int?, string, string, string, string, long?, string, string, string, short?, string, DateTime?, string, string)' Projectname D:\Programs\Projectname Software\Projectname\Projectname\Frmnewuser.cs  53  Active

请帮帮我。

【问题讨论】:

  • 您的方法需要一个可为空的 int 作为第一个参数,但您将它传递给一个字符串
  • userssave 收到 14 个参数,你发送了 13 个。

标签: c# mysql linq


【解决方案1】:

您发送的参数少于所需的参数,这就是 address 变为 null 的原因。

var db = new class1DataContext();
db.userssave( ' missing paramater ',txtusername.Text, txtfirstname.Text, txtlastname.Text, txtgender.Text, mobile, txtcountry.Text, txtemail.Text, txtrealestate.Text, Convert.ToInt16(level), txtsocialid.Text, txtdate.Value, txtpassword.Text, txtaddress.Text);

这里只有13个参数

.userssave(int?, string, string, string, string, long?, string, string, string, short?, string, DateTime?, string, string)

方法有14个参数

【讨论】:

  • 感谢您的回答,但在我的数据库中,第一个参数是主要的自动填充键,而在数据库过程中,我没有在代码中编写它。
  • @polrealestate 你能分享更多你想要做什么的信息
  • @polrealestate 字段配置为 在您的数据库中 无关紧要,因为这是 C# 代码。您不能将参数标记为“自动生成”在 C# 中,您为采用 14 个参数的方法提供了 13 个参数。如果你在这个方法中打算忽略第一个参数,你可以这样做,但是你仍然需要向它传递一个参数
【解决方案2】:

那是我的数据库程序。

Picture From database procedures

但是数据库表有另一个列(int),但我没有在我的代码中调用它,我想自动填充它,因为我设置了它:int NOT NULL PRIMARY KEY IDENTITY,

【讨论】:

    【解决方案3】:

    谢谢大家;我试试这段代码,问题就解决了。

    var db = new class1DataContext();
    db.userssave(null, txtusername.Text, txtfirstname.Text, txtlastname.Text, txtgender.Text, mobile, txtcountry.Text, txtemail.Text, txtrealestate.Text, Convert.ToInt16(level), txtsocialid.Text, txtdate.Value, txtpassword.Text, txtaddress.Text);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-04
      • 2013-10-17
      • 1970-01-01
      • 1970-01-01
      • 2020-12-18
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多