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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to input excel file interactively?

how to input excel file interactively?

Scheduled Pinned Locked Moved ASP.NET
databasesysadminsecuritytutorialquestion
1 Posts 1 Posters 1 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.
  • M Offline
    M Offline
    mijan
    wrote on last edited by
    #1

    I have a code that can automtically insert the content of excel file into sql database. But what i want is non hardcoded part.which is user can browse through the file using browse function and choose the excel file that they want. When we click submit then everything is saved to the sql database. First of all i have this code: Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" _ & "Data Source=" & Server.MapPath("../ExcelData.xls") _ & ";" & "Extended Properties=Excel 8.0") ' Open connection with the database. Try objConn.Open() ' Create new OleDbCommand to return data from worksheet. Dim objCmdSelect As New OleDbCommand("SELECT * FROM Range ", objConn) ' Create new OleDbDataAdapter that is used to build a DataSet ' based on the preceding SQL SELECT statement. Dim objAdapter1 As New OleDbDataAdapter ' Pass the Select command to the adapter. objAdapter1.SelectCommand = objCmdSelect ' Create new DataSet to hold information from the worksheet. Dim objDataset1 As New DataSet ' Fill the DataSet with the information from the worksheet. objAdapter1.Fill(objDataset1, "XLData") Dim xldt As New DataTable objAdapter1.Fill(xldt) objAdapter1.Dispose() ' objConn.Close() DataGrid1.DataSource = objDataset1.Tables(0).DefaultView DataGrid1.DataBind() ' Clean up objects. objConn.Close() Dim conn As New SqlConnection("workstation id=x;packet size=4096;user id=sa;data source=x;persist security info=True;initial catalog=Gx;password=x") conn.Open() Dim da As New SqlDataAdapter("select * from TEST_DATA", conn) Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da) Dim ds As New DataSet da.Update(ds, "TEST_DATA") For Each xlrow As DataRow In xldt.Rows Dim dr As DataRow = ds.Tables("TEST_DATA").NewRow For Each col As DataColumn In ds.Tables("TEST_DATA").Columns dr(col.ColumnName) = xlrow(col.ColumnName) Next ds.Tables("TEST_DATA").Rows.Add(dr)

    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