Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
please help me how to bind Excel data into database in #-tier archietecture...

C#
String strConnection = "Data Source=MySystem;Initial Catalog=MySamplesDB;Integrated Security=True";
        //file upload path
        string path = fileuploadExcel.PostedFile.FileName;
        //Create connection string to Excel work book
        string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";
        ////Create Connection to Excel work book
        OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
        ////Create OleDbCommand to fetch data from Excel
        OleDbCommand cmd = new OleDbCommand("Select [Id],[Name],[Designation],[Address] from [Sheet1$]", excelConnection);
        excelConnection.Open();
        OleDbDataReader dReader;
        dReader = cmd.ExecuteReader();
        SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
        //Give your Destination table name
        sqlBulk.DestinationTableName = "Excel_table";
        sqlBulk.WriteToServer(dReader);
        excelConnection.Close();


this is the code in Single tier..
But i dont know how to convert this code into 3-tier please help me...
Posted
Updated 15-Oct-12 3:55am
v3
Comments
bbirajdar 15-Oct-12 8:32am    
What is a # tier application?
[no name] 15-Oct-12 9:56am    
There is no conversion. You are confused on what a tier is and is not. You would simply put this code in your data access layer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900