VB.NET 0位没有行

时间:2012-06-12 20:51:21

标签: database vb.net datagridview

这是我在活动中的代码"双击" “家庭数据网格视图”表格 - 为了显示表单上的详细信息:

" showrow()"是一个根据数据库索引填写表单的子。 dsFamilies-DataSet,daFamilies-DataAdapter,counter - 全局变量

Private Sub dtgFamilies_CellContentDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgFamilies.CellContentDoubleClick

    counter = e.RowIndex
    ShowRow() // the problem: "There is no row at position 0" while my Data Base is //abound with data.
    Dim i As Integer = 0
    For i = 0 To (dsFamilies.Tables.Item("tblFamilies").Rows.Count - 1)
        If (dsFamilies.Tables("tblFamilies").Rows(i).Item("familyId") = dtgFamilies.Rows(counter).Cells(0).Value) Then
            counter = i
            ShowRow()

        End If
    Next
    tbControlFml.SelectTab(1)
End Sub



Sub ShowRow()

    txtId.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyId")
    txtFirstName.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyFirstName")
    txtLastName.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyLastName")
    txtStreet.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyAdress")
    comboCity.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyCity")
    txtHouseNum.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyHouseNum")
    txtPhoneNum.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyTeleNum")
    txtCellNum.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyCellNum")
    txtEmail.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyEmail")
    txtNumPeoFamily.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyPeopleNum")
    chkChild.Checked = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyChildren")
    chkChild.Checked = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyBaby")
    comboPckType.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyPackgId")
    chkAvailable = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyAvailable")
    comboEntityApp = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyAppEntityId")
    dtpJoin.Value = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyJoinDate")
    txtRemark.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyRemark")

    Dim subPhone As String = txtPhoneNum.Text.Substring(0, 2)
    Dim subCellPhone As String = txtCellNum.Text.Substring(0, 3)
    If ((subPhone = "077") Or (subPhone = "02") Or (subPhone = "03") Or (subPhone = "04") Or (subPhone = "08") Or (subPhone = "09")) Then
        comboPhoneIni.Text = subPhone
        txtPhoneNum.Text = txtPhoneNum.Text.Substring(2, 7)
    End If
    If ((subCellPhone = "050") Or (subCellPhone = "052") Or (subCellPhone = "054") Or (subCellPhone = "057")) Then
        comboCellIni.Text = subCellPhone
        txtCellNum.Text = txtCellNum.Text.Substring(3, 7)
    End If

End Sub

我想获得您可以提供的任何信息。谢谢! :)

1 个答案:

答案 0 :(得分:0)

这意味着这些使用数据库结果的计数值不包括DGV行:

    Private Sub dtgFamilies_CellContentDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgFamilies.CellContentDoubleClick 
        For i As Int16 = 0 To dtgFamilies.Rows.Count - 1 
            For e As Int16 = 0 To (dsFamilies.Tables.Item("tblFamilies").Rows.Count - 1) 
                If (dsFamilies.Tables("tblFamilies").Rows(e).Item("familyId") = dtgFamilies.Item(0, i).Value) Then 
                   counter = i 
                   Call ShowRow() 
                End If 
            Next e
        Next i
        tbControlFml.SelectTab(1) 
    End Sub 

    Sub ShowRow() 

        txtId.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyId") 
        txtFirstName.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyFirstName") 
        txtLastName.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyLastName") 
        txtStreet.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyAdress") 
        comboCity.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyCity") 
        txtHouseNum.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyHouseNum") 
        txtPhoneNum.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyTeleNum") 
        txtCellNum.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyCellNum") 
        txtEmail.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyEmail") 
        txtNumPeoFamily.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyPeopleNum") 
        chkChild.Checked = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyChildren") 
        chkChild.Checked = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyBaby") 
        comboPckType.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyPackgId") 
        chkAvailable = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyAvailable") 
        comboEntityApp = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyAppEntityId") 
        dtpJoin.Value = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyJoinDate") 
        txtRemark.Text = dsFamilies.Tables("tblFamilies").Rows(counter).Item("familyRemark") 

        Dim subPhone As String = txtPhoneNum.Text.Substring(0, 2) 
        Dim subCellPhone As String = txtCellNum.Text.Substring(0, 3) 
        If ((subPhone = "077") Or (subPhone = "02") Or (subPhone = "03") Or (subPhone = "04") Or (subPhone = "08") Or (subPhone = "09")) Then 
            comboPhoneIni.Text = subPhone 
            txtPhoneNum.Text = txtPhoneNum.Text.Substring(2, 7) 
        End If 
        If ((subCellPhone = "050") Or (subCellPhone = "052") Or (subCellPhone = "054") Or (subCellPhone = "057")) Then 
            comboCellIni.Text = subCellPhone 
            txtCellNum.Text = txtCellNum.Text.Substring(3, 7) 
        End If 

    End Sub 

它将逐一比较。