从VB.NET背后的代码填充radGrid

时间:2014-06-05 19:43:29

标签: vb.net telerik-grid

我有一个radGrid,我正在尝试填写代码,虽然我的查询返回4行,网格一直空出来。 这是我用来填充网格的代码:

 Dim DataRowTM As DataRow

        For Each DataRowTM In dt.Rows
            '' getting maxdate for a specefique type mineur for a specefique user
            Dim idTM As String = DataRowTM.Item("ID")
            Dim nomTM As String = DataRowTM.Item("Nom")
            Dim nbrjourTM As Integer = DataRowTM.Item("NbrJour")
            Dim iduser As String = Session("id")

            '' choosing the cars for each 
            Dim queryvoit As String
            queryvoit = "Select ID from Voiture where Voiture.IdUtilisateur =" + iduser
            Dim sqlComdV As New SqlCommand(queryvoit, con)
            Dim sqlAdpV As New SqlDataAdapter(sqlComdV)
            Dim dsV As New DataSet
            Dim dtV As New DataTable

            sqlAdpV.Fill(dsV, "voiture")
            dtV = dsV.Tables("voiture")

            Dim DataRowVoit As DataRow
            If dtV.Rows.Count > 0 Then
                For Each DataRowVoit In dtV.Rows
                    Dim idvoit As String = DataRowVoit.Item("ID")

                    'getting data from depense 
                    Dim QueryDepense As String
                    QueryDepense = "SELECT TypeMineur.Nom AS Type, Voiture.Marque + ' - ' + Voiture.Model AS Voiture, Depense.DateTime AS Date, Depense.Detail as Detail, TypeMineur.NbrJour AS NombreJour, DATEADD(day, TypeMineur.NbrJour, Depense.DateTime) AS DateNotif, Voiture.Marque, Voiture.Model FROM Depense INNER JOIN Voiture ON Depense.IdVoiture = Voiture.ID INNER JOIN TypeMineur ON Depense.IdTypeMineur = TypeMineur.ID WHERE (DATEADD(day, TypeMineur.NbrJour, Depense.DateTime)>= GETDATE() AND DATEADD(day, TypeMineur.NbrJour, Depense.DateTime)<= DATEADD(day,7,GETDATE())) AND (Depense.IdTypeMineur = " + idTM + ") AND (Depense.IdVoiture = " + idvoit + ") AND (Depense.DateTime IN (SELECT MAX(Depense_1.DateTime) AS Expr1 FROM Depense AS Depense_1 INNER JOIN Voiture AS Voiture_1 ON Depense_1.IdVoiture = Voiture_1.ID INNER JOIN TypeMineur AS TypeMineur_1 ON Depense_1.IdTypeMineur = TypeMineur_1.ID WHERE (Depense_1.IdTypeMineur = " + idTM + ") AND (Depense_1.IdVoiture = " + idvoit + ")))"

                    Dim sqlComd2 As New SqlCommand(QueryDepense, con)
                    Dim sqlAdp2 As New SqlDataAdapter(sqlComd2)
                    Dim ds2 As New DataSet
                    'Dim dt2 As New DataTable

                    sqlAdp2.Fill(ds2, "Depense")
                    dt2 = ds2.Tables("Depense")

                    Dim DataRowDep As DataRow
                    If dt2.Rows.Count > 0 Then

                        For Each DataRowDep In dt2.Rows
                            Dim NomType As String = DataRowDep.Item("Type")
                            Dim Voiture As String = DataRowDep.Item("Voiture")
                            Dim DateV As String = DataRowDep.Item("Date")
                            Dim Detail As String = DataRowDep.Item("Detail")
                            Dim NombreJour As Integer = DataRowDep.Item("NombreJour")
                            Dim DateNotif As String = DataRowDep.Item("DateNotif")

                            Dim Row1 As DataRow
                            Row1 = Table1.NewRow()

                            Row1.Item(0) = NomType
                            Row1.Item(1) = Voiture
                            Row1.Item(2) = DateV
                            Row1.Item(3) = Detail
                            Row1.Item(4) = NombreJour
                            Row1.Item(5) = DateNotif

                            Table1.Rows.Add(Row1)
                        Next
                    End If

                Next
            End If

        Next
    End If

    'RadGrid1.DataSource = Table1
    'RadGrid1.DataBind()

    con.Close()        
    GridView1.DataSource = Table1
    'GridView1.DataBind()

请帮忙!!!即使使用grid.databind它也不起作用!!

0 个答案:

没有答案