Click to See Complete Forum and Search --> : How to create a datatable in which you can join the data from excel sheet&db?


MathewJose
April 9th, 2007, 11:25 PM
Hi,

Anyone plzzhelp!!!!!!!

How do we create a datatable in which you can join the data from excel sheet and db ?I need to use the new table as the datasource ,in c#.Net windows application.


Plz help!!!

tiago.teixeira
April 10th, 2007, 06:47 AM
Hi

For deal with XLS files as a datasource you can make a simple OleDBConnection, see this example http://www.codeproject.com/office/excel_using_oledb.asp

I hope it can help.

Regards,
Teixeira

MathewJose
April 10th, 2007, 07:14 AM
have a datagrid which has a column that contains certain names that r populated from database.I need to copy a portion from excel and place it against each names.

I copied excel sheet content to a datatable ,then names from db to another one .Now i need to add both to a single datatable.then only i can bind it to grid.... I dont know how to do this.

Anyone who has done similiar type plz do send sample code.

taladon
April 17th, 2007, 02:10 PM
I've done this in the past. It's not too bad.

First create your OleDbConnection :

OleDbConnection excelcon = new OleDbConnection(Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1"; )

Open the connection

excelcon.Open();

Next Create your command:

string mycommand = @"SELECT * FROM [sheet1$]";

I use a Data Adapter and DataSet for managing my data, use whatever you feel comfortable with

DataSet thedataset = new DataSet();
OleDbDataAdapter theadapter = new OleDbDataAdapter(mycommand, excelcon);

Now fill the adapter

theadpater.Fill(thedataset);

Now you can bind the grid to the dataset

thegrid.DataSource = thedataset.Tables[0];

This code is purely from memory and I may have something backwards or not exactly correct but it should give you a good starting point in doing what you want. If you have questions, post and I'll answer as best as I can.

MathewJose
April 20th, 2007, 12:22 AM
Thank u so much for the help!!!!

I have another doubt.

I have selected a set of cells in a datagrid in Windows Application.
I need to fine out the ROW/COLUMN index of the selectd cells.

When i use current cell index,i get only the index of last cell that is selectd ..How do we get the row & column index of first cell...?