Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
Hi Buddies,
Since I'm new to, can anyone guide me to understand the codings for uploading excel file into sql server 2000 in VB.Net. I need brief explanation on this. Kindly response me as a procedure so that it is easy to understand and help me to enhance it.c I'm waiting for your replies. contact me @
Posted 27-Nov-12 17:17pm
Edited 27-Nov-12 17:20pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

First you need to import excel to datatable and then, connect datatable in your sql sever. The pre-condition of below code is that there is a datatable already existing in your database, and the datatable has the same structure with the original Excel file.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
      Dim workbook As Workbook = New Workbook
      Dim sheet As Worksheet = workbook.Worksheets(0)
      Dim data As DataTable = sheet.ExportDataTable
      'set the string connection to be the local databasestring
      Dim connectionStr As String = ""
      Dim conn As SqlConnection = New SqlConnection(connectionStr)
      Dim i As Integer = 0
      Do While (i < data.Rows.Count)
          Dim row As DataRow = data.Rows(i)
          Dim columnCount As Integer = data.Columns.Count
          Dim columns() As String = New String((columnCount) - 1) {}
          Dim j As Integer = 0
          Do While (j < columnCount)
              columns(j) = row(j).ToString
              j = (j + 1)
          ' suppose there are only three columns in your datatable
          Dim command As SqlCommand = New SqlCommand(("insert into DataTableSample(column1,column2,column3) values('"  _
                          + (columns(0) + ("','"  _
                          + (columns(1) + (" ','"  _
                          + (columns(2) + "')")))))))
          i = (i + 1)
  End Sub
to perform above code, you may need download an Excel component:[^]

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

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 28 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100