I want to link my vb.net form to excel sheet to extract data from the excel

时间:2017-10-12 09:48:01

标签: vb.net

Imports System.Data.OleDb

Public Class Form1
Dim conn As New OleDbConnection
Dim comm As New OleDbCommand
Dim dreader As OleDbDataReader
Dim str As String = ""
Dim wheelbase As String

Function CreateconnString(ByVal Str As String) As String
    Return "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Str + ";Extended Properties=""Excel 8.0;HDR=YES;"""
End Function

Private Sub SEARCH_Click(sender As Object, e As EventArgs) Handles SEARCH.Click
    wheelbase = "wheelbase"
    conn.ConnectionString = CreateconnString("C:\Users\shshaik\Desktop\sample.xlsx")


    comm.Connection = conn
    comm.CommandText = "SELECT * FROM [Sheet1$] where name= " & Chr(39) & wheelbase & Chr(39)
    conn.Open()
    dreader = comm.ExecuteReader(CommandBehavior.CloseConnection)

End Sub
End Class

this is my user form

my excel sample sheet

** when i click the search button in my form giving the serial no the data which is present in the excel sheet should appear in the respective text boxes of the userform in vb..**

0 个答案:

没有答案