Export data

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
LVL 18
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

How did you get the data into the datagrid in the first place? Typically datagrids are bound to a DataTable or DataSet object .
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.

vbturboAuthor Commented:
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 ...

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

vbturboAuthor Commented:
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
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.

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:-(


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vbturboAuthor Commented:
Hi there

worked another way around my problem

but any way thanks a lot

rgds jens
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.