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. Export a sheet of excel to a table Sql-Server

Export a sheet of excel to a table Sql-Server

Scheduled Pinned Locked Moved ASP.NET
databasehelpcsharpasp-netsql-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.
  • S Offline
    S Offline
    Sandraa
    wrote on last edited by
    #1

    Hi all , again :) I continue with my problem of export excel to sql-server. I got export sheets of excel to a table of sql-server with this code:

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    'Path of file in machine of user
    Label2.Text = System.IO.Path.GetFullPath(FileUpload1.PostedFile.FileName)
    Dim connString As String = _
    "Provider = Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source = " & "'" & Label2.Text & "';" & _
    "Extended Properties = 'Excel 8.0;HDR=Yes'"
    Dim cnn As New OleDbConnection(connString)
    Try
    Dim sql As String = _
    "INSERT INTO T_Recibos " & _
    "IN ''[ODBC;DRIVER={SQL Server};" & _
    "Server=Ip_Server;" & _
    "Database=NameDatabase;" & _
    "UID=User;" & _
    "PWD=password]" & _
    "SELECT Id_Comunidad, Id_finca FROM [Hoja1$]"
    Dim cmd As New OleDbCommand(sql, cnn)
    cnn.Open()
    Dim n As Integer = cmd.ExecuteNonQuery()
    Label1.Text = "Número de registros afectados: " & n.ToString
    Catch ex As OleDbException
    Label1.Text = (ex.Errors(0).Message)
    Catch ex As Exception
    Label1.Text = (ex.Message)
    Finally
    ' Cerramos la conexión
    cnn.Close()
    cnn = Nothing
    End Try
    End Sub
    End Class

    Now my problem is the next, when I try it from my web(not IIS local) and from Sql-Server allocated in my server (not my local Sql-Server) I receive a error that say me that doesn't find the excel file. I understand why, the problem is that the path only work if the file excel is in the same server that SQL-Server. A solve will be upload the file excel and later make all but I want to know if is possible with asp.net make it directly from file excel allocate in local machine of user to Sql-Server allocated in a server far of user. Thanks again by all I am a little desespetare with this :confused:

    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