473,385 Members | 1,372 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,385 software developers and data experts.

Inserting excel column into specific sql table column

Can someone please explain to me how to select a specific column in an excel spreadsheet and import the information in that column to an sql table in a c# windows application. Let's say my excel spreadsheet is full of first and last names and dates. What I want to do is take column "A" and insert the names in that column into an sql table with the column name "first_name". And I want to do the same thing for the last name column

Example
Let's say my excel spreadsheet has the following
Excel
Column A Column B Column C
jack johnson 4/2/2007
tim jackson 3/6/1995
ricky thomas 1/2/2090
bobby moore 4/2/1997

I want to take Column A and insert in the SQL table Person in the column firstname

Can you please help me with some code.
this is very important,

any help will be appreciated
Jul 23 '07 #1
2 2431
tifoso
41
If u try and show some code more help will come your way

Open an object(Excel type) , browse to the sheet/columns you are interested
and insert into your table

Ciao
Jul 23 '07 #2
If u try and show some code more help will come your way

Open an object(Excel type) , browse to the sheet/columns you are interested
and insert into your table

Ciao
Here's what I tried:
// Connection String to Excel Workbook
string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Documents and Settings\saharris\My Documents\first_last_name.xls;Extended Properties=""Excel 8.0;HDR=YES;""";

// Create Connection to Excel Workbook
using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
{
OleDbCommand command = new OleDbCommand("Select firstname FROM [first_last_name$]", connection);

connection.Open();

// Create DbDataReader to Data Worksheet
using (OleDbDataReader dr = command.ExecuteReader())
{
// SQL Server Connection String
string sqlConnectionString = "Data Source=myIpaddress;Initial Catalog=master;User=myUserName;Password=myPassword ";

// Bulk Copy to SQL Server
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName = "GUEST";
bulkCopy.WriteToServer(dr);
}
}
}
}
Jul 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: R. Santiago | last post by:
I have a table cc_rd_user_questions with the following columns: NUM NUMBER (25) DEFAULT 1 NOT NULL, COMPANY_ID NUMBER (15) NOT NULL, PROJ_ID NUMBER (15) NOT NULL, SEQ ...
8
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though...
3
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet...
3
by: Art at ABE Computer Consultants | last post by:
I'm missing something really simple, I'm sure. I have a form to be filled in. The operator choosed a plant species (the botanical name) from a list in a combo box. (The lookup table is populated...
2
by: pontifikas | last post by:
The Main Question Where Can I find the Class Documentation for OWC(Office Web Components)? I want to find how to tell to an Excel column to accept specific data types of input values. The...
2
by: Meaney | last post by:
Hi, I'm relatively new when using Access so bear with me. I have an Excel file with 4 spreadsheets, each with multiple columns Tbl.Schools SchoolName SchoolCity SchoolPop
9
by: dba123 | last post by:
I need some help and direction on what classes and an example or two (article) on how to read an Excel Worksheet and insert one column into a database table column. I am using .NET 2.0 only. What...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

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.