Solved

Convert Datatable to Ilist

Posted on 2010-11-15
4
920 Views
Last Modified: 2012-06-21
I have a RadGrid project that uses drag and drop with IList Data handling the data transfers.

My problem is that I need to populate one of the grids with data FIRST.  So...

My attached code will populate my grid using a datatable.

What I NEED to do is convert the Datatable to an IList named ShippedOrdersStore and use that as the datasource.
Protected Sub grdCollateral_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs)

        Dim objConn1 As SqlConnection

        objConn1 = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnPortal"))

        Dim oCom1 As SqlCommand

        oCom1 = New SqlCommand

        oCom1.Connection = objConn1

        oCom1.CommandText = "sp_cfa_TestCollateral"

        oCom1.CommandType = CommandType.StoredProcedure

        Dim dA As SqlDataAdapter = New SqlDataAdapter(oCom1)

        Dim myDataTable As DataTable = New DataTable()

        objConn1.Open()

        Try

            dA.Fill(myDataTable)

        Finally

            objConn1.Close()

        End Try

        grdCollateral.DataSource = myDataTable.DefaultView

        grdCollateral.GroupingSettings.CaseSensitive = False

        objConn1.Dispose()

        oCom1.Dispose()

        oCom1 = Nothing

    End Sub

Open in new window

0
Comment
Question by:lrbrister
  • 2
4 Comments
 
LVL 7

Expert Comment

by:kovilpattiBalu
ID: 34135836
hi,
here is ther code

public static IList<T> ConvertTo<T>(DataTable table)
    {
        if (table == null)
            return null;
 
        List<DataRow> rows = new List<DataRow>();
 
        foreach (DataRow row in table.Rows)
            rows.Add(row);
 
        return ConvertTo<T>(rows);
    }
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 34163399
If you are still interested, here is the VB.NET code

Replace

        Try
            dA.Fill(myDataTable)
        Finally
            objConn1.Close()
        End Try
        grdCollateral.DataSource = myDataTable.DefaultView


with
        Dim MyList as List(of DataRow)
        Try
            dA.Fill(myDataTable)
            For Each dRow in myDataTable.Rows
                  MyList.Add(dRow)
            Next
        Finally
            objConn1.Close()
        End Try
        grdCollateral.DataSource = MyList
0
 

Author Closing Comment

by:lrbrister
ID: 34172250
Thanks
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34172290
Glad to help :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb.net 2 37
SlingPlayer alternatives 1 36
Windows ICD FFU Issue 4 15
Code works but it's slow 24 45
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now