473,837 Members | 1,993 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OleDb DataSet Retrieving Data from Excel Placing into a SQLTable

My Question is this, I'm having trouble getting the OleDbDataAdapte r 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.FileNa me;
string sConn = @"Provider=Micr osoft.Jet.OLEDB .4.0;" +
"Data Source="+File+@ ";" +
"Extended Properties=Exce l 8.0;";
OleDbConnection DC =new OleDbConnection (sConn);
DC.Open();
OleDbCommand OC =new OleDbCommand("S ELECT * FROM [Sheet1$]"",DC);
OleDbDataAdapte r OA =new OleDbDataAdapte r();
OA.SelectComman d=OC;
DataSet DS =new DataSet();
DataTable custTable = DS.Tables.Add(" Global");
OA.Fill(DS,"Glo bal");

//--> Clone the old DataSet and create new pointer to DS2
string Oconn = @"Integrated Security=SSPI;P acket 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;Prov ider=""SQLOLEDB .1"";Workstatio n 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();
OleDbDataAdapte r OA2 =new OleDbDataAdapte r();
OA2.SelectComma nd=OC2;

Nov 22 '05 #1
1 1966
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***@discussi ons.microsoft.c om> wrote in message
news:74******** *************** ***********@mic rosoft.com...
My Question is this, I'm having trouble getting the OleDbDataAdapte r 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.FileNa me;
string sConn = @"Provider=Micr osoft.Jet.OLEDB .4.0;" +
"Data Source="+File+@ ";" +
"Extended Properties=Exce l 8.0;";
OleDbConnection DC =new OleDbConnection (sConn);
DC.Open();
OleDbCommand OC =new OleDbCommand("S ELECT * FROM [Sheet1$]"",DC);
OleDbDataAdapte r OA =new OleDbDataAdapte r();
OA.SelectComman d=OC;
DataSet DS =new DataSet();
DataTable custTable = DS.Tables.Add(" Global");
OA.Fill(DS,"Glo bal");

//--> Clone the old DataSet and create new pointer to DS2
string Oconn = @"Integrated Security=SSPI;P acket 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;Prov ider=""SQLOLEDB .1"";Workstatio n 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();
OleDbDataAdapte r OA2 =new OleDbDataAdapte r();
OA2.SelectComma nd=OC2;

Nov 22 '05 #2

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

Similar topics

1
382
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 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...
0
967
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 = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & FileName & "; Extended Properties=Excel 8.0;" Dim objConn As New System.Data.OleDb.OleDbConnection(strConn) objConn.Open() ' Create objects ready to grab data
1
6905
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 itself (asp.net recycled?); it also can be solved by restarting IIS. Any ideas what cause(s) this to happen? System.Data.OleDb.OleDbException: Unspecified error at System.Data.OleDb.OleDbDataReader.ProcessResults(Int32 hr) at...
0
302
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 out of Excel using OleDB, and suddenly, some of the data was not being extracted from Excel. I use OleDb for the extract into a DataTable and from there an SqlClient.SqlCommand to put it into SQL Server.
1
8959
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 and display in a datagrid. When the code executes I get: System.Data.OleDb.OleDbException: Could not find installable ISAM
0
5685
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 System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet) at TryThis.Form1.save() in C:\Documents and Settings\Nick\My Documents\...
2
6512
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 it. How does one get the metadata about a database thru DotNet? Thanks.
4
6417
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 'System.Data.OleDb.OleDbPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed." And appears the following message: System.Exception {System.Security.SecurityException} Any idea to solve this error? I work with VS...
1
1838
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 the microsoft excel 'xx' object library. 'you need two text boxes and two command buttons'on the form, an excel file in c:\book1.xls Dim xl As New Excel.Application Dim xlsheet As Excel.Worksheet Dim xlwbook As Excel.Workbook Private Sub...
1
10424
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 data by using ASP.NET, ADO.NET, and Visual C# .NET I am trying with the same code in Visual Studio 2005 in ASP.NET application. The code i am using is: protected void Page_Load(object sender, EventArgs e) { String connectionString...
0
9846
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9686
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10890
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10634
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9416
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7819
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7007
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5855
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3127
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.