本文介绍了OleDbException未处理:VB.NET与MS Access中的查询值和目标字段数不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的同事们,
我已经解决了这个问题6天了,几乎要放弃了。我想要的只是当我点击保存按钮时,它将添加到数据库和datagridview。这是我的以下代码:
在模块2中:
Dear fellow programmers,
I am coping with this problem for 6 days already and nearly gonna give up. All I want is when I click the 'Save' button it will add to the database and datagridview. This is my following code:
In Module 2:
Module Module2
Public con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\EncodingComplete.accdb")
End Module
在frmEncode:
In frmEncode:
Public Class frmEncode
Public Sub Add_Data()
con.Open()
Dim rs As New OleDb.OleDbCommand("Insert Into EncodingComplete(Client, Address, Date_Bill, BusStyle_Name, Vessel, TIN, Port, [Pier No], InterPleader1, InterPleader2, Call_Date, Call_Time, Call_VoyageNo, Call_ReceiveBy, VesselType, VesselCalls, FixedFee_ExcessCum, FixedFee_Amount, FixedFee_Rate, FixedFee_Total, OilyExcessCum, OilyRate, OilyAmnt, OilyTotal, GarbageExcessCum, GarbageRate, GarbageAmnt, GarbageTotal, NoxiousExcessCum, NoxiousRate, NoxiousAmnt, NoxiousTotal, Other, OtherExcessCum, OtherRate, OtherAmnt, OtherTotal, DollarConvers, AmountDue, PaymentDetails, TypeofPayment, DateofPayment, OrNo, Amount, Collector, BI, CSR) VALUES('" & ComboBoxEx1.Text & "', '" & TextBoxX1.Text & "', '" & DateTimePicker1.Text & "', '" & TextBoxX11.Text & "', '" & TextBoxX2.Text & "', '" & TextBoxX3.Text & "', '" & ComboBoxEx2.Text & "', '" & TextBoxX12.Text & "', '" & ComboBoxEx4.Text & "', '" & ComboBoxEx5.Text & "', '" & TextBoxX6.Text & "', '" & TextBoxX9.Text & "', '" & TextBoxX4.Text & "', '" & TextBoxX10.Text & "', '" & ComboBoxEx3.Text & "', '" & ComboBoxEx8.Text & "', '" & TextBoxX14.Text & "', '" & TextBoxX40.Text & "', '" & TextBoxX31.Text & "', '" & TextBoxX49.Text & "', '" & TextBoxX16.Text & "', '" & TextBoxX29.Text & "', '" & TextBoxX38.Text & "', '" & TextBoxX47.Text & "', '" & TextBoxX15.Text & "', '" & TextBoxX30.Text & "', '" & TextBoxX39.Text & "', '" & TextBoxX48.Text & "', '" & TextBoxX17.Text & "', '" & TextBoxX28.Text & "', '" & TextBoxX37.Text & "', '" & TextBoxX46.Text & "', '" & TextBoxX13.Text & "', '" & TextBoxX18.Text & "', '" & TextBoxX8.Text & "', '" & TextBoxX36.Text & "', '" & TextBoxX45.Text & "', '" & TextBoxX50.Text & "', '" & TextBoxX51.Text & "', '" & TextBoxX52.Text & "', '" & ComboBoxEx7.Text & "', '" & TextBoxX53.Text & "', '" & TextBoxX54.Text & "', '" & TextBoxX55.Text & "', '" & TextBoxX56.Text & "')", con)
rs.ExecuteNonQuery()
con.Close()
Display_Data()
End Sub
Private Sub Display_Data()
con.Open()
Dim dt As New DataTable("EncodingComplete")
Dim rs As New OleDb.OleDbDataAdapter("Select * from EncodingComplete", con)
rs.Fill(dt)
DataGridViewX1.DataSource = dt
DataGridViewX1.Refresh()
rs.Dispose()
con.Close()
End Sub
Private Sub ButtonX10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX10.Click
Add_Data()
End Sub
错误抛出
The error throws at
rs.ExecuteNonQuery()
说 OleDbException未处理:查询值和目标字段数不一样。
请帮助我。任何建议都将不胜感激。
saying OleDbException was unhandled: Number of query values and destination fields are not the same.
Please help me. Any suggestions would be appreciated.
推荐答案
这篇关于OleDbException未处理:VB.NET与MS Access中的查询值和目标字段数不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!