Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Importing Data from Excel sheet to the Database

Importing Data from Excel sheet to the Database

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestioncsssql-server
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 4645177
    wrote on last edited by
    #1

    Hi... I am developing a project called Info Dial....I got stuck at a place where i have to store an excel sheet into a database that can be displayed in a grid view....thats working fine for a single Excel sheet...but what if i have more than one excel shhets :( ??How can i overcome this problem? I have my code as shown.... if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.ContentLength > 0) { string fn = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName); string savelocation = @"D:\programs\" + fn; FileUpload1.PostedFile.SaveAs(savelocation); string excelConnectionString = ("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + savelocation + ";" + "Extended Properties=Excel 8.0;"); // Create Connection to Excel Workbook OleDbConnection connection = new OleDbConnection(excelConnectionString); OleDbCommand command = new OleDbCommand("Select * FROM [Sheet1$]", connection); connection.Open(); // Create DbDataReader to Data Worksheet System.Data.OleDb.OleDbDataReader dr = command.ExecuteReader(); // SQL Server Connection String string sqlConnectionString = "Database=Infodial;server=s156;uid=sa;pwd=sa"; // Bulk Copy to SQL Server SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString); bulkCopy.DestinationTableName = "companydetails"; bulkCopy.WriteToServer(dr); connection.Close(); ScriptManager.RegisterStartupScript(Page, this.GetType(), "alert", "<script>alert('Saved in Database Successfully');</script>", false); } Any code would be appreciated... Thanks in Advance Regards Abhishek.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups