Display table data in bound datagridview

Posted on 2006-05-31
Last Modified: 2010-05-18
Hi Experts,

I did a SQL Bulk copy to a database table and I need to view the data in a datagridview that is bound to that table.

I am using a Parent/Child form.

Thanks in advance,

Question by:dave_sky
    LVL 2

    Expert Comment

    //This is a way for databinding, I assume you are asking the way for databinding:
    // Also you already have a datagrid defined and its instance name is DataGrid1
    using System.Data.Odbc;

    //assume you are using Odbc, you can change your connection type to anothers
    OdbcConnection Connection = new OdbcConnection("Your connection string here");

    OdbcCommand cmd = new OdbcCommand();
    cmd.CommandText = "Your SQL Query statement here"
    cmd.Connection = Connection;

    DataSet ds = new DataSet();
    OdbcDataAdapter da = new OdbcDataAdapter();
    da.SelectCommand = cmd;


    DataGrid1.DataSource = ds;

    // Any question please reply

    Author Comment

    I think I better rephrase the question.

    I think a better description would be:

    I want to copy data from Datatable A to Datatable B.

    The Datagridview, connected to Datatable B, is already bound to the Database table.

    I hope this is more clear,

    LVL 2

    Accepted Solution

    It seems that you want to copy datasource from one to another.  

    I suggest you create the SQL queries yourself  by popup the data from Datatable A

    1:  Popup data from DataTable A, row by row
    2:  For each row, create SQL QUERY, like INSERT INTO DataTable B  ... VALUES (?, ? ... ?)

    ' Note: The column name can be retrieved through DataSet
    ' Also, use binding variables will be the best to deal with different types.

    I've developed a business software using the above approach and the performance is quite good.

    If you need help, please let me know.

    Author Comment

    Sorry to say, I need a lot of help... I've researched all the material  I can find on this subject and I still just don't 'get it'.

    I tried the SQL BulkCopy from table to table, that works, but I can't get the Child datagridview to sychronize with the parent.

    I would appreciate it if you could break it down more,



    Author Comment

    I found this code snippet, maybe it will make things easier for you.

    BulkCopy Datasource from one to another:

    Dim dr As SqlDataReader
                Dim conn As New SqlConnection(Conn_str)
                Dim conn1 As New SqlConnection(Conn_str1)
                Dim sqlc As New SqlCommand("Select * from Orders", conn)
                'dr = sqlc.ExecutePageReader(CommandBehavior.CloseConnection, 10, 10)
                dr = sqlc.ExecuteReader(CommandBehavior.CloseConnection)
                Dim dt As New DataTable("Orders")
                Dim bulkcopy As New SqlBulkCopy(conn1)
                bulkcopy.DestinationTableName = "MVPOrders"

    2 questions:
    I don't understand (Conn_str1)?
    Which event handler do I use for this?




    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    761 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

    12 Experts available now in Live!

    Get 1:1 Help Now