0

I have a more data in excel file .so i have to import it into sql database using vb.net.can anyone send the source code?

1
  • 1
    Try this link, it should have what you need tinyurl.com/yaogvne Commented Apr 5, 2010 at 9:57

2 Answers 2

2
Dim ExcelConnection As New 

System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\MyExcelSpreadsheet.xlsx; Extended Properties=""Excel 12.0 Xml; HDR=Yes""")
ExcelConnection.Open()

Dim expr As String = "SELECT * FROM [Sheet1$]"
Dim objCmdSelect As OleDbCommand = New OleDbCommand(expr, ExcelConnection)
Dim objDR As OleDbDataReader

Dim SQLconn As New SqlConnection()
Dim ConnString As String = "Data Source=MMSQL1; Initial Catalog=DbName; User Id=UserName; Password=password;"
SQLconn.ConnectionString = ConnString
SQLconn.Open()

Using bulkCopy Asd SqlBulkCopy = New SqlBulkCopy(SQLConn)
bulkCopy.DestinationTableName = "TableToWriteToInSQLSERVER"

  Try
    objDR = objCmdSelect.ExecuteReader
    bulCopy.WriteToServer(objDR)
    objDR.Close()
    SQLConn.Close()

  Catch ex As Exception
    MsgBox(ex.ToString)
  End Try
End Using
Sign up to request clarification or add additional context in comments.

Comments

1

If it's a one-off job, use DTS or SSIS. No code required.

Otherwise, you can open Excel as a data source, suck up its contents and insert into your database.

11 Comments

ok but i want in vb.net code because we have 1000's of files to import tats y
That's a fair bit of work and relies on intimate knowledge of your particular circumstances. No one on SO is going write it for you.
but i"m using file browser to get the excel file from the path and then i have to convert this is my process actually can u help
Sorry, but that doesn't make things any clearer. Actually, I'm more confused about you want than before.
ok i'll explain it clearly ..i have more than 1000 files in the excel format.from tat i have to import into sql database by using windows form using vb.net. In tat i have File upload to choose the file to covert... this is my main objective.can u help me now?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.