在listview中单击一次时出现EOF和BOF错误 - vb 2008

时间:2015-01-29 13:13:43

标签: eof

我的问题是,当我点击listview中的数据时,我收到了该错误。谁能帮我 :( 这是我的代码

公共类frmRegister     Sub Clear()         txtID.Text =""         txtFAN.Text =""         txtFN.Text =""         txtMI.Text =""         txtAD.Text =""         cboCS.Text =""         cboSEX.Text =""         DateTimePicker.Text =""         txtEDUC.Text =""         txtEMP.Text =""         txtPOPD.Text =""         txtYEARS.Text =""         txtMONTH.Text =""         cboProg.Text =""

End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If txtFAN.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtFAN.Focus() : Exit Sub : End If
    If txtFN.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtFN.Focus() : Exit Sub : End If
    If txtMI.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtMI.Focus() : Exit Sub : End If
    If txtAD.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtAD.Focus() : Exit Sub : End If
    If cboCS.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : cboCS.Focus() : Exit Sub : End If
    If cboSEX.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : cboSEX.Focus() : Exit Sub : End If
    If DateTimePicker.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : DateTimePicker.Focus() : Exit Sub : End If
    If txtEDUC.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtEDUC.Focus() : Exit Sub : End If
    If txtEMP.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtEMP.Focus() : Exit Sub : End If
    If txtPOPD.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtPOPD.Focus() : Exit Sub : End If
    If txtYEARS.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtYEARS.Focus() : Exit Sub : End If
    If txtMONTH.Text = "" Then : MsgBox(" Don't leave space !", MsgBoxStyle.Exclamation) : txtMONTH.Focus() : Exit Sub : End If

    If MsgBox("Do you want to save this record ?", MsgBoxStyle.YesNo, "Message") = MsgBoxResult.No Then : Exit Sub : End If

    rs = New ADODB.Recordset

    With rs
        If LblAdd_Edit.Text = "Add" Then
            .Open("Select * from TableStudents", cn, 3, 3)
            .AddNew()
        Else
            .Open("Select * from TableStudents where No ='" & Me.Text & "'", cn)
        End If
        .Fields("No").Value = txtID.Text
        .Fields("FamName").Value = txtFAN.Text
        .Fields("FirstName").Value = txtFN.Text
        .Fields("MiddleInitial").Value = txtMI.Text
        .Fields("Address").Value = txtAD.Text
        .Fields("CivStatus").Value = cboCS.Text
        .Fields("Sex").Value = cboSEX.Text
        .Fields("BirthDate").Value = DateTimePicker.Text
        .Fields("EducAttain").Value = txtEDUC.Text
        .Fields("EmpType").Value = txtEMP.Text
        .Fields("POPD").Value = txtPOPD.Text
        .Fields("NoYears").Value = txtYEARS.Text
        .Fields("IncomeMonth").Value = txtMONTH.Text
        .Fields("Program").Value = cboProg.Text
        .Update()
        Clear()
    End With
    DisplayList()
End Sub

Private Sub frmRegister_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
    DisplayList()
End Sub

Private Sub frmRegister_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    connection()
    LblAdd_Edit.Text = "Add"

End Sub

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
    If MsgBox("Do you want to delete this record ?", MsgBoxStyle.YesNo, "Message") = MsgBoxResult.No Then : Exit Sub : End If
    rs = New ADODB.Recordset
    rs.Open("select * from TableStudents where No like '" & Me.Text & "'", cn, 3, 3)
    rs.Delete()
    DisplayList()
End Sub

Private Sub lv1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lv1.MouseClick



    'Try
    txtID.Enabled = False
    rs = New ADODB.Recordset
    With rs
        .Open("Select * from TableStudents where No Like '" & lv1.FocusedItem.Text & "'", cn, 3, 3)
        txtID.Text = .Fields("No").Value
        txtFAN.Text = .Fields("FamName").Value
        txtFN.Text = .Fields("FirstName").Value
        txtMI.Text = .Fields("MiddleInitial").Value
        txtAD.Text = .Fields("Address").Value
        cboCS.Text = .Fields("CivStatus").Value
        cboSEX.Text = .Fields("Sex").Value
        DateTimePicker.Text = .Fields("BirthDate").Value
        txtEDUC.Text = .Fields("EducAttain").Value
        txtEMP.Text = .Fields("EmpType").Value
        txtPOPD.Text = .Fields("POPD").Value
        txtYEARS.Text = .Fields("NoYears").Value
        txtMONTH.Text = .Fields("IncomeMonth").Value
        cboProg.Text = .Fields("Program").Value
        .MoveNext()
    End With

    'Catch ex As Exception
    'MsgBox(ex.ToString)
    'End Try
End Sub
Sub DisplayList()


    Dim lst
    lv1.Items.Clear()
    rs = New ADODB.Recordset

    With rs
        .Open("select * from TableStudents", cn, 3, 3)
        Do While Not .EOF
            lst = New ListViewItem
            lst = lv1.Items.Add(.Fields("No").Value)
            lst.SubItems.Add(.Fields("FamName").Value)
            lst.SubItems.Add(.Fields("FirstName").Value)
            lst.SubItems.Add(.Fields("MiddleInitial").Value)
            lst.SubItems.Add(.Fields("Address").Value)
            lst.SubItems.Add(.Fields("CivStatus").Value)
            lst.SubItems.Add(.Fields("Sex").Value)
            lst.SubItems.Add(.Fields("BirthDate").Value)
            lst.SubItems.Add(.Fields("EducAttain").Value)
            lst.SubItems.Add(.Fields("EmpType").Value)
            lst.SubItems.Add(.Fields("POPD").Value)
            lst.SubItems.Add(.Fields("NoYears").Value)
            lst.SubItems.Add(.Fields("IncomeMonth").Value)
            lst.SubItems.Add(.Fields("Program").Value)
            .MoveNext()
        Loop

    End With
End Sub
Private Sub lv1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lv1.SelectedIndexChanged
    Me.Text = lv1.FocusedItem.Text
End Sub

Private Sub btnEDIT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEDIT.Click
    Me.Text = lv1.FocusedItem.Text
    LblAdd_Edit.Text = "Edit"
End Sub

结束班

0 个答案:

没有答案