Results 1 to 5 of 5

Thread: Query CSV data in Dataset

  1. #1

    Thread Starter
    Hyperactive Member Dodger's Avatar
    Join Date
    Mar 2001
    Posts
    433

    Question Query CSV data in Dataset

    Hey All,

    I have loaded CSV data into a dataset, but I'm not sure how to query this dataset with SQL, is it possible?

    TIA.

    _Dodger.

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    You do something like this
    VB Code:
    1. Dim rows() as DataRow = MyDS.Table("myTable").Select(SQL statement here)
    Hope that helps.

  3. #3

    Thread Starter
    Hyperactive Member Dodger's Avatar
    Join Date
    Mar 2001
    Posts
    433
    Hi DevGrp,

    Here is my code, it seems to be selecting the correct number of rows, but all data is null, I'm obviously doing something wrong (new to .NET). Please assist if you can.

    Code:
            Dim fxDataSet As New Data.DataSet()
            Dim fxTable As New DataTable()
            Dim fxFile As StreamReader = New StreamReader("C:\_Trading\History\25-06-03_02-09-03.txt")
    
            With fxTable.Columns
                .Add("Date")
                .Add("Price")
            End With
    
            While fxFile.Peek <> -1
                fxTable.Rows.Add(Split(fxFile.ReadLine, ",", , CompareMethod.Text))
            End While
    
            Dim rows() As DataRow = fxTable.Select("Units = ' 150'")
    
            fxTable.Clear()
    
            Dim i As Integer
            For i = 0 To rows.GetUpperBound(0)
                fxTable.Rows.Add(rows(i))
            Next
    
            fxDataSet.Tables.Add(fxTable)
            DataGrid1.DataSource = fxDataSet
    
            TextBox1.Text = fxDataSet.Tables(0).Rows.Count()
    TIA.

    _Dodger.

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    If you are doing it like that, then you can just use a DataView. I'll post some code when I get home.

  5. #5

    Thread Starter
    Hyperactive Member Dodger's Avatar
    Join Date
    Mar 2001
    Posts
    433
    Thanks DevGrp! I think I have it working correctly.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width