locked
how to copy records in datatable? RRS feed

  • Question

  • hi all

    i used this code:

        Public Sub SampleQ1()
            Dim Dc As New DataClasses1DataContext
            Dim S = From qq In Dc.Persons Where qq.Kind = 3
            DataGridView1.DataSource = S
        End Sub

    now 

    i want copy result into a data table in dataset..

    how to do it?

    please help  me

    thanks


    Name of Allah, Most Gracious, Most Merciful and He created the human

    Thursday, November 1, 2012 7:23 PM

Answers

  • Hi sh2013;

    This code that you posted :

    Public Sub SampleQ1()
        Dim Dc As New DataClasses1DataContext
        Dim S = From qq In Dc.Persons Where qq.Kind = 3
        DataGridView1.DataSource = S
    End Sub
    

    Does not use a DataSet or DataTable to display the result of the Linq query. It uses the DataContext of the of the model. Therefore to add items to the DataGridView the items need to be added to the DataContext and update to the database and then re-assign the results of the query back to the DataGridView to refresh its values.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Alexander Sun Thursday, November 22, 2012 6:34 AM
    Friday, November 2, 2012 5:41 PM

All replies

  • There is no conversion from a Linq query to a DataTable and therefore you will need to create a DataSet and a DataTable and add the DataTable to the DataSet. Then create columns for the DataTable and add them to the DataTable. Once that is done then you iterate through the results creating a new row and setting the values of the row and add the row to the DataTable.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Thursday, November 1, 2012 8:31 PM
  • thanks dear

    i have a dataset in my project

    Dataset1

    i have a data table in my project 

    Person data table have 4 columns:

    personid  kind  lname fname

      Public Sub SampleQ1()
            Dim Dc As New DataClasses1DataContext
            Dim S = From qq In Dc.Persons Where qq.Kind = 3
            DataGridView1.DataSource = S
        End Sub


    how to do add row in my data table by top code!

    please example by code

    thanks


    Name of Allah, Most Gracious, Most Merciful and He created the human


    • Edited by sh 2020 Friday, November 2, 2012 5:13 AM
    Friday, November 2, 2012 4:53 AM
  • please help me


    Name of Allah, Most Gracious, Most Merciful and He created the human

    Friday, November 2, 2012 12:36 PM
  • Hi sh2013;

    This code that you posted :

    Public Sub SampleQ1()
        Dim Dc As New DataClasses1DataContext
        Dim S = From qq In Dc.Persons Where qq.Kind = 3
        DataGridView1.DataSource = S
    End Sub
    

    Does not use a DataSet or DataTable to display the result of the Linq query. It uses the DataContext of the of the model. Therefore to add items to the DataGridView the items need to be added to the DataContext and update to the database and then re-assign the results of the query back to the DataGridView to refresh its values.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Alexander Sun Thursday, November 22, 2012 6:34 AM
    Friday, November 2, 2012 5:41 PM