Link to home
Start Free TrialLog in
Avatar of Ryan Smith
Ryan SmithFlag for United States of America

asked on

VB.net - getting data from excel spreadsheet for textboxes

I really hope I ask this question right. I’m, working on a vb.net application that uses excel as a database. I have dropdown box that selects a person’s name. The name is an exact match to a column in the excel database. I have the database connection setup and its working great.

The trouble I’m having is trying to get the data for that person into the textboxes in my application. All the data for the person is on the same row as the person’s name… example. The person Halle Berry name is on A2 in the excel spread sheet and all her data is on B2, C2, D2 and E2.

Private Function CreateConnString(ByVal Str As String) As String
        Return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Str + ";Extended Properties=""Excel 8.0;HDR=YES;User ID=user01;Password=ThePassword;"""
    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim Conn As New OleDbConnection
        Dim Comm As New OleDbCommand
        Dim DReader As OleDbDataReader
        Dim Str As String = ""
        Dim Ename = EmpName.Text
        Conn.ConnectionString = CreateConnString("c:\data\TimeData.xls")
        Comm.Connection = Conn
        Comm.CommandText = "Select" + Ename + "From [Einfo$]"""

    End Sub

Open in new window


In my code above I have it going to the Einfo sheet and selecting the employee name (Ename). How do i tell it to read the data on it's row and put it in the textboxes?
ASKER CERTIFIED SOLUTION
Avatar of Kimputer
Kimputer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ryan Smith

ASKER

I'll try this when i get home.. Also the first row in my spreadsheet are titles.  Ename is the textbox in my application (EmpName.Text) that has the user name. But i think this is what I'm looking for.
Avatar of jyothi kuna
jyothi kuna

getting error at  Conn.Open()
and here only one textbox is there where is the remaining   textbox and  from where u  get that connection string