Solved

Convert Datatable to Ilist

Posted on 2010-11-15
4
908 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

11 Experts available now in Live!

Get 1:1 Help Now