Uploading an excel file in a SQL Server Database

Jellybaby

Newcomer
Joined
Feb 12, 2004
Messages
14
Hi

I am trying to upload an excel spreadsheet into a SQL Server database through a upload web front end. I would appreciate if anyone would know where to obtain code examples on this.

Thanks
 
first of all you have to upload (fileupload) the .xls file from the client-machine to the server.

then open the excel-file on the server, read the informations and write them to the sql server...

all this can be done with ado.net

quick example to read excel:

Code:
string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\Excelfile.xls; Extended Properties=\"Excel 8.0;Text; HDR=No; IMEX=1; Mode=Read\";";
OleDbConnection conn = new OleDbConnection(ConnStr);
conn.Open();
string SQL = "Select * From Tablename";
OleDbDataAdapter Adapter = new OleDbDataAdapter(SQL, conn);
DataSet ds = new DataSet();
Adapter.Fill (ds);
conn.close();


foreach (DataRow r in ds.Tables[0].Rows)
{
	//insert into sql-server
}

Regards, WebJumper
 
Back
Top