[英]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.