473,396 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

OleDb DataSet Retrieving Data from Excel Placing into a SQLTable

My Question is this, I'm having trouble getting the OleDbDataAdapter to Point
to another connection string and pull the data out of the DataSet I created
from the Excel Spread Sheet and Place it up in a SQL table. I'm Sorry for the
mess of Code but I've been at this all Day now. If you have any Ideas I could
surely use the help.
Thank You,
Terry
string File = ofdExcel.FileName;
string sConn = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source="+File+@";" +
"Extended Properties=Excel 8.0;";
OleDbConnection DC =new OleDbConnection(sConn);
DC.Open();
OleDbCommand OC =new OleDbCommand("SELECT * FROM [Sheet1$]"",DC);
OleDbDataAdapter OA =new OleDbDataAdapter();
OA.SelectCommand=OC;
DataSet DS =new DataSet();
DataTable custTable = DS.Tables.Add("Global");
OA.Fill(DS,"Global");

//--> Clone the old DataSet and create new pointer to DS2
string Oconn = @"Integrated Security=SSPI;Packet Size=4096;Data
Source=""TVIT18\TVIT18"";Tag with column collation when
possible=False;Initial Catalog=IA;Use Procedure for Prepare=1;Auto
Translate=True;Persist Security
Info=False;Provider=""SQLOLEDB.1"";Workstation ID=TVIT13;Use Encryption for
Data=False";
OleDbConnection CO2 =new OleDbConnection(Oconn);
DataSet DS2 = new DataSet();
DS2 = DS.Clone(); //-->Clone DataSet
OleDbCommand OC2 = new OleDbCommand();
OleDbDataAdapter OA2 =new OleDbDataAdapter();
OA2.SelectCommand=OC2;

Nov 22 '05 #1
1 1940
Perhaps what you need to do is create a DataAdapter on your SQL Server
connection, and call update on it, passing your DataSet as a parameter.

I have my reservations whether that would work however, since the DataSet
stores internal changes to it's data relative to the original Data Source.
So eventually, maybe you'll have to loop through the DataSet & add the rows
manually to your SQL Server tables :(

Angel
O:]
"Terry" <Te***@discussions.microsoft.com> wrote in message
news:74**********************************@microsof t.com...
My Question is this, I'm having trouble getting the OleDbDataAdapter to Point to another connection string and pull the data out of the DataSet I created from the Excel Spread Sheet and Place it up in a SQL table. I'm Sorry for the mess of Code but I've been at this all Day now. If you have any Ideas I could surely use the help.
Thank You,
Terry
string File = ofdExcel.FileName;
string sConn = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source="+File+@";" +
"Extended Properties=Excel 8.0;";
OleDbConnection DC =new OleDbConnection(sConn);
DC.Open();
OleDbCommand OC =new OleDbCommand("SELECT * FROM [Sheet1$]"",DC);
OleDbDataAdapter OA =new OleDbDataAdapter();
OA.SelectCommand=OC;
DataSet DS =new DataSet();
DataTable custTable = DS.Tables.Add("Global");
OA.Fill(DS,"Global");

//--> Clone the old DataSet and create new pointer to DS2
string Oconn = @"Integrated Security=SSPI;Packet Size=4096;Data
Source=""TVIT18\TVIT18"";Tag with column collation when
possible=False;Initial Catalog=IA;Use Procedure for Prepare=1;Auto
Translate=True;Persist Security
Info=False;Provider=""SQLOLEDB.1"";Workstation ID=TVIT13;Use Encryption for Data=False";
OleDbConnection CO2 =new OleDbConnection(Oconn);
DataSet DS2 = new DataSet();
DS2 = DS.Clone(); //-->Clone DataSet
OleDbCommand OC2 = new OleDbCommand();
OleDbDataAdapter OA2 =new OleDbDataAdapter();
OA2.SelectCommand=OC2;

Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Terry | last post by:
My Question is this, I'm having trouble getting the OleDbDataAdapter to Point to another connection string and pull the data out of the DataSet I created from the Excel Spread Sheet and Place it up...
0
by: EMW | last post by:
I use the following function to read an Excel worksheet into a dataset: Public Function GetDataFromExcel(ByVal FileName As String, ByVal ds As DataSet) As Boolean Try Dim strConn As String =...
1
by: T8 | last post by:
I have a asp.net (framework 1.1) site interfacing against SQL 2000. It runs like a charm 99% of the time but once in a while I get the following "unspecified error". Sometimes it would resolve by...
0
by: Brian Hanson | last post by:
Hi, I have an unusual problem that just showed its ugly head at a pretty bad time. I have an asp.net (VB) app that takes data from an Excel sheet and puts it into SQL Server. I get the data...
1
by: Roger Twomey | last post by:
I have a form that allows a user to upload a microsoft Excel Spreadsheet. (I am testing with one created in Excel 2000) The spreadsheet is uploaded correctly. It is then supposed to be read...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
2
by: sloan | last post by:
Back in ADO days, it was fairly easy to get the meta data (tablenames, columnnames , etc) .. with all that schema stuff. I have a Access database, that I'd like to get the list of tableNames in...
4
by: Abel | last post by:
Hi I try to execute an sample how to read and write excel sheets using OleDb When opens the connection, the objConn.Open gave me this error: "Request for the permission of type...
1
by: rishiyo | last post by:
Good ones!! I want to retrieve and add datas with excel. I've tried one by adding two textboxes and two command buttons. THE code is: 'do declare these variables you need to add a reference'to...
1
by: =?Utf-8?B?U2hlZXMgQWJpZGk=?= | last post by:
I read an article on the link: http://support.microsoft.com/default.aspx?scid=kb;en-us;306572 related to reading data from Excel using OLEDB The topic's heading is: How to query and display excel...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.