保存已编辑的记录VB.NET时出错

时间:2016-09-15 08:19:48

标签: database vb.net datagridview

我使用.Updatean unhandled exception in...在datagridview中保存我的记录。我也使用访问数据库,在一个表中有145个字段。保存已修改的记录时,我收到Too many fields defined错误并收到其他消息Imports System.Data.OleDb Public Class Info Inherits System.Windows.Forms.Form Private Sub bday1_ValueChanged(sender As Object, e As EventArgs) Handles bday.ValueChanged Dim d1, d2 As Date Dim days, months, years As Long d1 = bday.Value.ToShortDateString d2 = Now.ToShortDateString years = Year(d1) months = Month(d1) days = d1.Day years = Year(d2) - years months = Month(d2) - months days = d2.Day - days If Math.Sign(days) = -1 Then days = 30 - Math.Abs(days) months = months - 1 End If If Math.Sign(months) = -1 Then months = 12 - Math.Abs(months) years = years - 1 End If age.Text = years.ToString 'TextBox2.Text = months.ToString 'TextBox3.Text = days.ToString End Sub Private Sub add1_Click(sender As Object, e As EventArgs) Handles add1.Click comname2.Enabled = True posi2.Enabled = True deptm2.Enabled = True tm2.Enabled = True reason2.Enabled = True add2.Enabled = True End Sub Private Sub add2_Click(sender As Object, e As EventArgs) Handles add2.Click comname3.Enabled = True posi3.Enabled = True deptm3.Enabled = True tm3.Enabled = True reason3.Enabled = True add3.Enabled = True End Sub Private Sub add3_Click(sender As Object, e As EventArgs) Handles add3.Click comname4.Enabled = True posi4.Enabled = True deptm4.Enabled = True tm4.Enabled = True reason4.Enabled = True add4.Enabled = True End Sub Private Sub add4_Click(sender As Object, e As EventArgs) Handles add4.Click comname5.Enabled = True posi5.Enabled = True deptm5.Enabled = True tm5.Enabled = True reason5.Enabled = True add5.Enabled = True End Sub Private Sub add5_Click(sender As Object, e As EventArgs) Handles add5.Click comname6.Enabled = True posi6.Enabled = True deptm6.Enabled = True tm6.Enabled = True reason6.Enabled = True add6.Enabled = True End Sub Private Sub add6_Click(sender As Object, e As EventArgs) Handles add6.Click comname7.Enabled = True posi7.Enabled = True deptm7.Enabled = True tm7.Enabled = True reason7.Enabled = True add7.Enabled = True End Sub Private Sub add7_Click(sender As Object, e As EventArgs) Handles add7.Click comname8.Enabled = True posi8.Enabled = True deptm8.Enabled = True tm8.Enabled = True reason8.Enabled = True add8.Enabled = True End Sub Private Sub add8_Click(sender As Object, e As EventArgs) Handles add8.Click comname9.Enabled = True posi9.Enabled = True deptm9.Enabled = True tm9.Enabled = True reason9.Enabled = True add9.Enabled = True End Sub Private Sub add9_Click(sender As Object, e As EventArgs) Handles add9.Click comname10.Enabled = True posi10.Enabled = True deptm10.Enabled = True tm10.Enabled = True reason10.Enabled = True End Sub Private Sub Info_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the '_Employees__RecordDataSet._employees__record' table. You can move, or remove it, as needed. Me.Employees__recordTableAdapter.Fill(Me._Employees__RecordDataSet._employees__record) End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Add.Click EmployeesRecordBindingSource.AddNew() TextBox1.Text = getAutoId enableall() End Sub Private Function getAutoId() As Integer If Me.DataGridView.Rows.Count = 0 Then getAutoId = 1 Else getAutoId = Me.DataGridView.Rows(Me.DataGridView.Rows.Count - 1).Cells(0).Value + 0 End If End Function Private Sub btnReg_Click(sender As Object, e As EventArgs) Handles btnReg.Click On Error GoTo dito Dim D1, D2, D3, D4 As Date D1 = bday.Value.ToShortDateString D2 = Now.ToShortDateString D3 = date1.Value.ToShortDateString D4 = date1.Value.ToShortDateString If D1 >= D2 Then MessageBox.Show("Birthday must not be less than or equal to current date!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) bday.Value = Now.Date ElseIf fname.Text = "" Then MessageBox.Show("Insert First Name Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) ElseIf lname.Text = "" Then MessageBox.Show("Insert Last Name Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) ElseIf mi.Text = "" Then MessageBox.Show("Insert Middle Initial Name Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) ElseIf address.Text = "" Then MessageBox.Show("Insert Address Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) ElseIf age.Text <= 17 Then MessageBox.Show("Age must be 18yrs. and above.", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) ElseIf sex.Text = "" Then MessageBox.Show("Choose Sex Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) ElseIf contact.Text = "" Then MessageBox.Show("Insert Contact Number Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) ElseIf dept1.Text = "" Then MessageBox.Show("Insert Department Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) ElseIf pos1.Text = "" Then MessageBox.Show("Insert Position Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) ElseIf civil.Text = "" Then MessageBox.Show("Choose Civil Status Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Else EmployeesRecordBindingSource.EndEdit() Employees__recordTableAdapter.Update(Me._Employees__RecordDataSet._employees__record) MessageBox.Show("Record Save!", "Success!") disableall() End If dito: Exit Sub End Sub Private Sub civil_SelectedIndexChanged(sender As Object, e As EventArgs) If civil.SelectedItem = "Married" Then spouse.Enabled = True ElseIf civil.SelectedItem = "Widowed" Then spouse.Enabled = True ElseIf civil.SelectedItem = "Legally Separated" Then spouse.Enabled = True ElseIf civil.SelectedItem = "Anulled" Then spouse.Enabled = True Else spouse.Enabled = False End If End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click enableall() End Sub Private Sub enableall() lname.Enabled = True fname.Enabled = True mi.Enabled = True bday.Enabled = True sex.Enabled = True natio.Enabled = True address.Enabled = True contact.Enabled = True father.Enabled = True mother.Enabled = True tin.Enabled = True sss.Enabled = True pagibig.Enabled = True phh.Enabled = True stat.Enabled = True dept1.Enabled = True pos1.Enabled = True rm.Enabled = True date1.Enabled = True civil.Enabled = True termiresi.Enabled = True date2.Enabled = True heduc.Enabled = True elem.Enabled = True y1.Enabled = True hs.Enabled = True y2.Enabled = True col.Enabled = True y3.Enabled = True deg.Enabled = True pdeg.Enabled = True ts.Enabled = True y4.Enabled = True other.Enabled = True childno.Enabled = True childone.Enabled = True childtwo.Enabled = True childthree.Enabled = True childfour.Enabled = True childfive.Enabled = True childsix.Enabled = True childseven.Enabled = True childeight.Enabled = True childnine.Enabled = True btnReg.Enabled = True End Sub Private Sub disableall() lname.Enabled = False fname.Enabled = False mi.Enabled = False bday.Enabled = False sex.Enabled = False natio.Enabled = False address.Enabled = False contact.Enabled = False father.Enabled = False mother.Enabled = False tin.Enabled = False sss.Enabled = False pagibig.Enabled = False phh.Enabled = False stat.Enabled = False dept1.Enabled = False pos1.Enabled = False rm.Enabled = False date1.Enabled = False civil.Enabled = False termiresi.Enabled = False date2.Enabled = False heduc.Enabled = False elem.Enabled = False y1.Enabled = False hs.Enabled = False y2.Enabled = False col.Enabled = False y3.Enabled = False deg.Enabled = False pdeg.Enabled = False ts.Enabled = False y4.Enabled = False other.Enabled = False Add.Enabled = True btnReg.Enabled = False childno.Enabled = False childone.Enabled = False childtwo.Enabled = False childthree.Enabled = False childfour.Enabled = False childfive.Enabled = False childsix.Enabled = False childseven.Enabled = False childeight.Enabled = False childnine.Enabled = False End Sub Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click childno.Enabled = True childone.Enabled = True childtwo.Enabled = True childthree.Enabled = True childfour.Enabled = True childfive.Enabled = True childsix.Enabled = True childseven.Enabled = True childeight.Enabled = True childnine.Enabled = True End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click On Error GoTo dire If MessageBox.Show("Are you sure?", "Delete Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then EmployeesRecordBindingSource.RemoveCurrent() Employees__recordTableAdapter.Update(Me._Employees__RecordDataSet._employees__record) End If dire: Exit Sub End Sub End Class 。添加/保存新记录时工作正常。我的场地太多了吗?我已经读过每个表格的访问权限限制为255个字段...

trim

0 个答案:

没有答案