[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

Display table data in bound datagridview

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,

Dave
0
dave_sky
Asked:
dave_sky
  • 3
  • 2
1 Solution
 
akumanovaCommented:
//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");
Connection.Open();

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;
da.Fill(ds);

Connecction.Close();

DataGrid1.DataSource = ds;
DataGrid1.DataBound();

// Any question please reply
0
 
dave_skyAuthor Commented:
Hi,
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,

Dave
0
 
akumanovaCommented:
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

Steps:
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.
0
 
dave_skyAuthor Commented:
Hi,
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,

Thanks,

Dave
0
 
dave_skyAuthor Commented:
Hello,
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)
            conn.Open()
            conn1.Open()
            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"
            bulkcopy.WriteToServer(dr)

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

Thanks,

Dave

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now