473,785 Members | 3,067 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 1964
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
965
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
6898
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
8951
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
5676
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
6415
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
1830
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
10419
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
9645
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
10325
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...
0
10148
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6740
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
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.