Export data

Posted on 2004-10-28
Last Modified: 2010-04-24
Hi all

Is it possible to export the "data" content  in a datagrid to a database-table.... where
the number of collums and collumnames in the datagrid are same as the table in the database.?

And if so... how can i do that

thank's in advance

rgds jens
Question by:vbturbo
    LVL 14

    Expert Comment

    How did you get the data into the datagrid in the first place? Typically datagrids are bound to a DataTable or DataSet object .
    LVL 4

    Expert Comment

    Datagrids have a Datasource property. If the datagrid is not bound tothe database, then you are still able to use the DataSource property to get the data in a number of forms. One of the MSDN examples is as follows:

    Private Function GetDataSetFromDataSource() As DataSet
        ' Create a DataSet variable, and set it to the DataSource.
        Dim myDataSet As DataSet
        myDataSet = CType(dataGrid1.DataSource, DataSet)
        Return myDataSet
    End Function 'GetDataSetFromDataSource

    This dataset (or if you chose to use data table) can be used to do anumber of things to get the data into the database.

    LVL 18

    Author Comment

    Hi there

    thanks for quick reply

    Have load'ded the data in the datagrid from a dataset "the grid is not bound to a table"
    Afterwards i have been filtering the grid and now i want export the filtered result in to a new
    table in a access database  or better into a new dataset ex.... myDataSet

    ill try your above mentioned code and get back ...

    LVL 18

    Author Comment

    Hi Andrew

    did'nt have any succes with msdn suggestion so here is the code im useing

        Dim daprivatkunder As New OleDb.OleDbDataAdapter
        Dim dsprivatKlientAs New DataSet("Recordset")

     Private Sub cboadminstrtion_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboadminstrtion.SelectedIndexChanged

            Navnedata = cboadminstrtion.Text
            Call mySqlserver()
            If cbosøgeindex.Text <> "Søge parameter" Then
                Kundeidprivat = "x"
                strSQL = "SELECT * FROM Kundedata Where Kundeid like '" & Kundeidprivat & "%'"
                rst = con.Execute(strSQL)
                daprivatkunder.Fill(dsprivatKlient, rst, "Kundedata")

                DataGrid1.CaptionText = "Klient udvalg"
                DataGrid1.RowHeadersVisible = True
                DataGrid1.DataSource = dsprivatKlient
                DataGrid1.DataMember = "Kundedata"
            End If
          End Sub

    when im finished filtering the "dsprivatKlient/datagrid" i imagined that i could store/save the filteret
    data into a new dataset

    maybe you got a new suggestion..?

    rgds jens
    LVL 10

    Assisted Solution

    Why do you want to save the filtered data to a database?

    If you are not making any modifications to the data in the datagrid then there are no changes to be sent to the database.

    For sorting and filtering operations u can use the dataview.

    Private Sub SortByTwoColumns()
       ' Get the DefaultViewManager of a DataTable.
       Dim myDataView As DataView
       myDataView = DataTable1.DefaultView
       ' By default, the first column sorted ascending.
       myDataView.Sort = "State, ZipCode DESC"
    End Sub

    then u can use the dataview.Table property to get the inbound table from the dataview. U can then use this datatable to bind to the datagrid.
    LVL 4

    Accepted Solution


    I just frigged up and lost the last lot of code I had done for you...Its late here and I need some sleep.

    If you are still having issues in the morning I will re-post REALLY!!!! sorry:-(

    LVL 18

    Author Comment

    Hi there

    worked another way around my problem

    but any way thanks a lot

    rgds jens

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 ( But the ability to create custom scanning profiles a…
    Want to pick and choose which updates you receive? Feel free to check out this quick video on how to manage your email notifications.

    845 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

    9 Experts available now in Live!

    Get 1:1 Help Now