none
child list for field cannot created

    Question

  • Hi,

    I have this code behind a save button.

    As you see, I use a new dt datatable, add some rows, set the row values and then assign it to a dgv (on the bottom of the code).

    If I click the first time on the save button, the dgv is populated. If I click the second time, I get the error: child list for field "periodusok" cannot be created.

    Why?

    Thanks.

    dt = New DataTable
            dt.Columns.Add("Sorszám", Type.GetType("System.String"))
            dt.Columns.Add("Megnevezés", Type.GetType("System.String"))
            dt.Columns.Add("Kezdete", Type.GetType("System.String"))
            dt.Columns.Add("Vége", Type.GetType("System.String"))
            dt.Columns.Add("Vev. lez.", Type.GetType("System.Boolean"))
            dt.Columns.Add("Száll. lez.", Type.GetType("System.Boolean"))
            dt.Columns.Add("Bank/pt. lez.", Type.GetType("System.Boolean"))
            dt.Columns.Add("Fők. lez.", Type.GetType("System.Boolean"))
            dt.Columns.Add("Per. lez.", Type.GetType("System.Boolean"))
            Select Case cmbPerhossz.SelectedIndex
                Case 0 'hónap
                    phossz = DateDiff(DateInterval.Month, CDate(txtkezdet.Text), CDate(txtvege.Text))
                    datumpuffer = ""
                    For i = 1 To phossz + 1
                        dr = dt.NewRow
                        dr(0) = i
                        dr(1) = honapok(i + Val(txtkezdet.Text.Substring(5, 2)) - 2)
                        If i = 1 Then
                            dr(2) = txtkezdet.Text
                            dr(3) = LastDayOfMonth(CDate(txtkezdet.Text)).ToShortDateString
                            datumpuffer = LastDayOfMonth(CDate(txtkezdet.Text)).ToShortDateString
                        End If
                        If i > 1 And i < phossz + 1 Then
                            dr(2) = DateAdd(DateInterval.Day, 1, CDate(datumpuffer)).ToShortDateString
                            dr(3) = LastDayOfMonth(CDate(dr(2))).ToShortDateString
                            datumpuffer = LastDayOfMonth(CDate(dr(2))).ToShortDateString
                        End If
                        If i = phossz + 1 Then
                            dr(2) = FirstDayOfMonth(CDate(txtvege.Text)).ToShortDateString
                            dr(3) = txtvege.Text
                        End If
                        dt.Rows.Add(dr)
                    Next
                Case 1
                    'mennyi negyedév fér bele az intervallumba
                    phossz = DateDiff(DateInterval.Quarter, CDate(txtkezdet.Text), CDate(txtvege.Text))
                    datumpuffer = ""
                    For i = 1 To phossz + 1
                        dr = dt.NewRow
                        dr(0) = i
                        dr(1) = i & ". negyedév"
                        '1. per esetén a kezdés=txtpkezdes, a vég az aktuális negyedév vége
                        If i = 1 Then
                            dr(2) = txtkezdet.Text
                            dr(3) = LastDayOfQuarter(CDate(txtkezdet.Text)).ToShortDateString
                            datumpuffer = LastDayOfQuarter(CDate(txtkezdet.Text)).ToShortDateString
                        End If
                        'köztes per esetén negyedév a különbség a kezdet és a vég között
                        If i > 1 And i < phossz + 1 Then
                            dr(2) = DateAdd(DateInterval.Day, 1, CDate(datumpuffer)).ToShortDateString
                            dr(3) = LastDayOfQuarter(CDate(dr(2))).ToShortDateString
                            datumpuffer = LastDayOfQuarter(CDate(dr(2))).ToShortDateString
                        End If
                        'utolsó per esetén
                        If i = phossz + 1 Then
                            dr(2) = FirstDayOfQuarter(CDate(txtvege.Text)).ToShortDateString
                            dr(3) = txtvege.Text
                        End If
                        dt.Rows.Add(dr)
                    Next
            End Select
            'ha vannak zárási időszakok
            If txtzaroper.Text <> "" Then
                For i = 0 To Val(txtzaroper.Text) - 1
                    dr = dt.NewRow
                    dr(0) = dt.Rows(dt.Rows.Count - 1).Item(0) + 1
                    dr(1) = "Zárás - " & dr(0) & ". per."
                    dr(2) = txtvege.Text
                    dr(3) = txtvege.Text
                    dt.Rows.Add(dr)
                Next
            End If
            dt.TableName = "periodusok"
            gcPeriodusok.DataMember = "periodusok"
            gcPeriodusok.DataSource = dt

    Wednesday, January 16, 2013 7:25 PM

Answers

  • Remove it, it makes no sense in this context. It is ment in situation where you don't use the datasource.


    Success
    Cor

    • Marked as answer by DerStauner Wednesday, January 16, 2013 8:44 PM
    Wednesday, January 16, 2013 8:23 PM

All replies

  • I suggest that you put a breakpoint at the line Select Case cmbPerhossz.SelectedIndex, press F5 to debug, and see if the code follows the path you expect.

    --
    Andrew

    Wednesday, January 16, 2013 7:43 PM
  • no, this isn't the problem.

    the datatable has always its rows, I have already checked this.

    Wednesday, January 16, 2013 7:55 PM
  • Can you tell where you get the error, and try to set Option Strict on in your code, I see some code which do not fulfill that in my perception.


    Success
    Cor

    Wednesday, January 16, 2013 8:04 PM
  • I get the error on the line
    gcPeriodusok.DataMember = "periodusok"
    Wednesday, January 16, 2013 8:19 PM
  • Remove it, it makes no sense in this context. It is ment in situation where you don't use the datasource.


    Success
    Cor

    • Marked as answer by DerStauner Wednesday, January 16, 2013 8:44 PM
    Wednesday, January 16, 2013 8:23 PM
  • Thanks, great. It works now.
    Wednesday, January 16, 2013 8:44 PM