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. Import sheet excel to table in Sql Server with Asp.net (VB)

Import sheet excel to table in Sql Server with Asp.net (VB)

Scheduled Pinned Locked Moved ASP.NET
csharpdatabaseasp-netsql-server
9 Posts 2 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, I need import from excel to a table Sql-Server with asp.net and i am using vb.net, i have seen some sample but even I don't understand how work and all samples is in c# and i need vb.net. I have my conexion to sql server in web.config

    <appSettings>
    <add key="ConnectionString" value="Data Source=Mymachine;Initial Catalog=Database;Persist Security Info=False;user id=User;password=\*\*\*\*\*\*"/>
    

    </appSettings>

    for later I use a function for call it:

    Public Shared Function ObtenerCadenaConexion() As String
        Return ConfigurationManager.AppSettings("ConnectionString")
    End Function
    

    Someboy can help me? I need a sample easy for can import it from a web page Thanks very much

    C S 2 Replies Last reply
    0
    • S Sandraa

      Hi all, I need import from excel to a table Sql-Server with asp.net and i am using vb.net, i have seen some sample but even I don't understand how work and all samples is in c# and i need vb.net. I have my conexion to sql server in web.config

      <appSettings>
      <add key="ConnectionString" value="Data Source=Mymachine;Initial Catalog=Database;Persist Security Info=False;user id=User;password=\*\*\*\*\*\*"/>
      

      </appSettings>

      for later I use a function for call it:

      Public Shared Function ObtenerCadenaConexion() As String
          Return ConfigurationManager.AppSettings("ConnectionString")
      End Function
      

      Someboy can help me? I need a sample easy for can import it from a web page Thanks very much

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      The code you have written retrieves a connection from the web.config. It looks correct to me. What is the problem?

      *Developer Day Scotland - Free community conference Delegate Registration Open

      S 1 Reply Last reply
      0
      • C Colin Angus Mackay

        The code you have written retrieves a connection from the web.config. It looks correct to me. What is the problem?

        *Developer Day Scotland - Free community conference Delegate Registration Open

        S Offline
        S Offline
        Sandraa
        wrote on last edited by
        #3

        I believe that I explained bad, my problem is that I don't know import a sheet of excel to sql-server with my present connection. Regards

        C 1 Reply Last reply
        0
        • S Sandraa

          I believe that I explained bad, my problem is that I don't know import a sheet of excel to sql-server with my present connection. Regards

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          Sandraa wrote:

          I don't know import a sheet of excel to sql-server with my present connection.

          How do you want it imported? Do you want the excel file to be inserted as a binary object? Or do you want the excel spreadsheet to be translated into tables?

          *Developer Day Scotland - Free community conference Delegate Registration Open

          S 1 Reply Last reply
          0
          • C Colin Angus Mackay

            Sandraa wrote:

            I don't know import a sheet of excel to sql-server with my present connection.

            How do you want it imported? Do you want the excel file to be inserted as a binary object? Or do you want the excel spreadsheet to be translated into tables?

            *Developer Day Scotland - Free community conference Delegate Registration Open

            S Offline
            S Offline
            Sandraa
            wrote on last edited by
            #5

            I want import data from excel to a table sql-server. Not binary object. And if is possible can use my present conection to sql server from web.config Thanks

            C 1 Reply Last reply
            0
            • S Sandraa

              I want import data from excel to a table sql-server. Not binary object. And if is possible can use my present conection to sql server from web.config Thanks

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              Sandraa wrote:

              And if is possible can use my present conection to sql server from web.config

              The connection is the least of your problems. Personally, I'd look at using something like SSIS for what you want (SQL Server Integration Services) because that is what it is good at: Taking data from one source and loading it into SQL Server.

              *Developer Day Scotland - Free community conference Delegate Registration Open

              S 1 Reply Last reply
              0
              • C Colin Angus Mackay

                Sandraa wrote:

                And if is possible can use my present conection to sql server from web.config

                The connection is the least of your problems. Personally, I'd look at using something like SSIS for what you want (SQL Server Integration Services) because that is what it is good at: Taking data from one source and loading it into SQL Server.

                *Developer Day Scotland - Free community conference Delegate Registration Open

                S Offline
                S Offline
                Sandraa
                wrote on last edited by
                #7

                I am beginner, I accept all solutions :) The target is that from a web page a lot users can export data with a same template of excel in them hard disk to same table of sql-server. Later with all these data of table i will do web reports. Is not possible create a form for upload these data because these users has all data in excel and they want continue using excel. Thanks for help me.

                1 Reply Last reply
                0
                • S Sandraa

                  Hi all, I need import from excel to a table Sql-Server with asp.net and i am using vb.net, i have seen some sample but even I don't understand how work and all samples is in c# and i need vb.net. I have my conexion to sql server in web.config

                  <appSettings>
                  <add key="ConnectionString" value="Data Source=Mymachine;Initial Catalog=Database;Persist Security Info=False;user id=User;password=\*\*\*\*\*\*"/>
                  

                  </appSettings>

                  for later I use a function for call it:

                  Public Shared Function ObtenerCadenaConexion() As String
                      Return ConfigurationManager.AppSettings("ConnectionString")
                  End Function
                  

                  Someboy can help me? I need a sample easy for can import it from a web page Thanks very much

                  S Offline
                  S Offline
                  Sandraa
                  wrote on last edited by
                  #8

                  somebody can help me? I have this code of a button the idea is export from excel to a table of sql-server but i received a OleDbException "ODBC: falló la llamada." that the translate is "ODBC: error failed the call" I put you my code:

                  Imports Microsoft.VisualBasic
                  Imports System.Data
                  Imports System.Data.SqlClient
                  Imports System.Data.OleDb

                  Partial Class Formularios_ImportarExcel
                  Inherits System.Web.UI.Page

                  Protected Sub Page\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                  
                  End Sub
                  
                  Protected Sub Button1\_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
                  
                      Dim connString As String = \_
                          "Provider = Microsoft.Jet.OLEDB.4.0;" & \_
                          "Data Source = C:\\test.xls;" & \_
                          "Extended Properties = 'Excel 8.0;HDR=Yes'"
                  
                      Dim cnn As New OleDbConnection(connString)
                  
                      Try
                          Dim sql As String = \_
                              "SELECT \* INTO T\_Recibos " & \_
                              "IN ''\[ODBC;DRIVER={SQL Server};" & \_
                                   "Server=localmachine;" & \_
                                   "Database=NAMEDATABASE;" & \_
                                   "UID=Sandra;" & \_
                                   "PWD=Sandra\]" & \_
                              "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
                          cnn.Close()
                          cnn = Nothing
                  
                      End Try
                  End Sub
                  
                  S 1 Reply Last reply
                  0
                  • S Sandraa

                    somebody can help me? I have this code of a button the idea is export from excel to a table of sql-server but i received a OleDbException "ODBC: falló la llamada." that the translate is "ODBC: error failed the call" I put you my code:

                    Imports Microsoft.VisualBasic
                    Imports System.Data
                    Imports System.Data.SqlClient
                    Imports System.Data.OleDb

                    Partial Class Formularios_ImportarExcel
                    Inherits System.Web.UI.Page

                    Protected Sub Page\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                    
                    End Sub
                    
                    Protected Sub Button1\_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
                    
                        Dim connString As String = \_
                            "Provider = Microsoft.Jet.OLEDB.4.0;" & \_
                            "Data Source = C:\\test.xls;" & \_
                            "Extended Properties = 'Excel 8.0;HDR=Yes'"
                    
                        Dim cnn As New OleDbConnection(connString)
                    
                        Try
                            Dim sql As String = \_
                                "SELECT \* INTO T\_Recibos " & \_
                                "IN ''\[ODBC;DRIVER={SQL Server};" & \_
                                     "Server=localmachine;" & \_
                                     "Database=NAMEDATABASE;" & \_
                                     "UID=Sandra;" & \_
                                     "PWD=Sandra\]" & \_
                                "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
                            cnn.Close()
                            cnn = Nothing
                    
                        End Try
                    End Sub
                    
                    S Offline
                    S Offline
                    Sandraa
                    wrote on last edited by
                    #9

                    I found the error, the problem was that this part

                                "SELECT \* INTO T\_Recibos " & \_                "IN ''\[ODBC;DRIVER={SQL Server};" & \_                     "Server=localmachine;" & \_                     "Database=NAMEDATABASE;" & \_                     "UID=Sandra;" & \_                     "PWD=Sandra\]" & \_                "FROM \[Hoja1$\]"
                    

                    create a new table T_Recibos but I had it created in Sql-server, I changed it by T_Recibos2 (what doesn't exist) and work! Now my problem is that I want to have a table (created into sql) and little to little that users add to it more rows from excel. any idea?

                    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