简体   繁体   English

重载解析失败,因为没有可访问的“新”接受此数目的参数

[英]overload resolution failed because no accessible 'new' accepts this number of arguments

Help overload resolution failed because no accessible 'new' accepts this number of arguments. 帮助重载解析失败,因为没有可访问的“新”接受此数目的参数。 after i add another new MySqlDataAdapter then the blue lines showed up 在我添加另一个新的MySqlDataAdapter之后,蓝线出现了

Else
    ds = New DataSet
    da = New MySqlDataAdapter("INSERT INTO rel_receipt_details values('" & txtornum.Text & "','" & cboparticular.Text & "','" & txtamtpd.Text & "')", conn)
    da.Fill(ds)

    ds = New DataSet
    da = New MySqlDataAdapter("INSERT INTO tbl_receipt values('" & txtornum.Text & "','" & CInt(txtstudid.Text.Remove(0, 2)) & "','" & dtpdate.Text & "','" & txtcashier.Text & "')", conn)
    da.Fill(ds)

    ds = New DataSet
    da = New MySqlDataAdapter("INSERT INTO tbl_check values ('" & checkno.Text & "','" & CInt(txtstudid.Text.Remove(0, 2)) &  "','" & bankname.Text "','" &  bankbranch.Text & "')",conn)   '<-- Error on this line
    da.Fill(ds)

In the commented line you miss a & after the bankname.Text and the following "','" , but if you need to insert directly data in the database table from some input textbox then you should use a MySqlCommand with the appropriate command and ExecuteNonQuery with it. 在注释行中,您会错过bankname.Text和以下"','"之后的& ,但是如果您需要直接从某些输入文本框中将数据插入数据库表中,则应使用MySqlCommand以及相应的命令和ExecuteNonQuery用它。

So, just for example 所以,举例来说

  Dim cmdText = "INSERT INTO rel_receipt_details values(@p1,@p2,@p3)"
  Dim cmd = new MySqlCommand(cmdText,  conn)
  cmd.Parameters.AddWithValue("@p1", txtornum.Text)
  cmd.Parameters.AddWithValue("@p2", cboparticular.Text)
  cmd.Parameters.AddWithValue("@p3", txtamtpd.Text)
  cmd.ExecuteNonQuery()

Note that you should not write a command text using string concatenation. 请注意,您不应使用字符串串联来编写命令文本。 Use always a parameterized query to avoid Sql Injection and parsing problems caused by strings with embedded quotes or date formats or decimals symbols. 始终使用参数化查询来避免SQL注入和解析问题,这些问题是由带有嵌入式引号或日期格式或小数点符号的字符串引起的。

The code above should be repeated for the other two tables. 对于其他两个表,应重复以上代码。 (or you could build a single cmdText with the three commandtexts separated by a semicolon without forgetting the required parameters) (或者,您可以构建一个cmdText,其中三个命令文本之间用分号分隔,而不会忘记所需的参数)

As pointed out by a comment the DataAdapter will insert that data because it will blindly call ExecuteReader on the commandtext passed, but this is completely wrong from a logic point of view. 正如评论所指出的那样,DataAdapter将插入该数据,因为它将在传递的命令文本上盲目调用ExecuteReader,但是从逻辑角度来看,这是完全错误的。 A DataAdapter is used initially to retrieve records from the database and fill a DataSet and then, when you have made changes to the tables (via code or via a binding control like the DataGridView), call the Update method that executes the Insert, Update and Delete required. 首先使用DataAdapter从数据库检索记录并填充DataSet,然后在对表进行更改(通过代码或通过诸如DataGridView之类的绑定控件)后,调用执行Insert,Update和必须删除。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 重载解析失败,因为没有可访问的“ ExecuteScalar”接受此数量的参数 - Overload resolution failed because no accessible 'ExecuteScalar' accepts this number of arguments 重载解析失败,因为没有可访问的&#39;writealltext&#39;接受此数量的参数 - overload resolution failed because no accessible 'writealltext' accepts this number of arguments 重载解析失败,因为没有可访问的“参数”接受此数量的 arguments - Overload resolution failed because no accessible 'Parameters' accepts this number of arguments 尝试将stringbuilder文本写入批处理文件时,“由于没有可访问的&#39;New&#39;接受此数目的参数,所以过载解析失败” - “Overload resolution failed because no accessible 'New' accepts this number of arguments” when trying to write stringbuilder text into a batch file VB.NET MVC重载解析失败,因为没有可访问的“创建”接受此数量的参数 - VB.NET MVC Overload resolution failed because no accessible 'Create' accepts this number of arguments 重载解析失败,因为对于这些参数,没有可访问的“新”是最具体的 - Overload resolution failed because no accessible 'new' is most specific for these arguments 重载解析失败,因为没有可访问的“新”是这些参数最具体的: - Overload resolution failed because no accessible 'New' is most specific for these arguments: VBNET重载,因为没有可访问的“ int”接受数字参数 - VBNET Overload because no accessible 'int' accepts number arguments 重载解析失败,因为没有可访问的“ DataBind”最特定于这些参数 - overload resolution failed because no accessible 'DataBind' is most specific for these arguments 重载解决失败,因为无法使用这些参数调用可访问的“加入” - Overload resolution failed because no accessible 'Join' can be called with these arguments
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM