Re: VS2003 transfer data between two data sources
- From: Otis Mukinfus <phony@xxxxxxxxxxxxxxxx>
- Date: Sun, 09 Apr 2006 15:57:28 -0500
On Sun, 9 Apr 2006 13:23:01 -0700, AbeR <AbeR@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I am loading a DataSet from an access file (exported from another app that a
vendor provided) and want to appendthe data into an SQL Table that has the
same structure.
I can easily append rows to the SQL table, but that can't be a best
practice! Does anyone have any guidance as to taking the filled dataset from
excel and then doing an append to the SQL table without having to step
through all the rows (obviously the two have the same structure)
Currently:
private void TransferData()
string _eConnectionString;
// Connection string for the Excel file selected through UI into TextBox
fileName
_eConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
this.fileName.Text + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [CIPEXPORT$]", oConn);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
da.Fill(ds,"testData");
DataTable dt = new DataTable();
// Open up the SQL Server Connection
SqlConnectionConnection sConn = new SqlConnection(ConnectionString);
SqlCommand sCmd = new SqlCommand("_StoredProcedure", sConn);
SCmd.CommandType = CommandType.StoredProcedure;
sCmd.Parameters.Add("@Field1", SqlDbType.NvarChar, 10);
// list of fields by variable
// At this point what's the best/fastest method to transfer the dataset to
the Sql Server table? I could export to XML. There must be an easy method,
but I'm not fluent enough in ADO.NET yet.
Thanks!
Is this a one time exercise, or do you need to do it frequently? If you need to
do it frequently and have access to DTS on the MS SQL Server database, then
create a DTS package to do the transfer of data. Even if it's a one-timer you
can do it very easily with DTS.
If it must be done in an application, then I believe the best way is a row at a
time (but not with a DataSet), even though it may seem tedious, you might be
surprised how fast it is.
Question: In your question you say the file is an "access file", but in your
code you seem to be loading an Excel file. Just curious, not throwing rocks.
Good luck with your project,
Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
.
- Follow-Ups:
- Prev by Date: Re: query builder and derived table
- Next by Date: Re: VS2003 transfer data between two data sources
- Previous by thread: Re: INSERT Statement with Empty Date
- Next by thread: Re: VS2003 transfer data between two data sources
- Index(es):
Relevant Pages
|