Export data

Posted on 2004-10-28
Medium Priority
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

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

Expert Comment

ID: 12441083
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

ID: 12441384
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 ...

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

LVL 18

Author Comment

ID: 12441736
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

123654789987 earned 120 total points
ID: 12442974
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.

Accepted Solution

andrewharris earned 180 total points
ID: 12443396

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

ID: 12443444
Hi there

worked another way around my problem

but any way thanks a lot

rgds jens

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Jorge
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Suggested Courses
Course of the Month3 days, 6 hours left to enroll

598 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