Hi All,
I have 1 combo box and 1 textbox and an excel file. I need to populate the combo box through the data from my excel file which is EMP_ID and I managed to do that via OleDb.
This is the content of my excel file:
EMP_ID SPIDOM Password
0969 nalburo 123456
1840 molitan 123456
GO89 amarasigan 123456
GO91 elubat 123456
GO93 myocampo 123456
GO95 mtrillana 123456
GU49 ptordecillas 123456
GU50 jalmazan 123456
GU51 jluna 123456
Now, I wanted my program to do this, when I select the the EMP_ID in my combo box, the textbox will be auto-filled up with the corresponding SPIDOM of the EMP_ID, how can I do that? For example, I've selected 0969 from the combo box, the textbox value will be nalburo.
Here's my current code:
Imports System.Data
Public Class authorization
Private Sub authorization_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
passTextbox.Enabled = False
Try
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='tnt.xls';Extended Properties=Excel 8.0;")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
MyCommand.TableMappings.Add("EMP_ID", "EMP_ID")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
ComboBox1.DataSource = DtSet.Tables(0)
ComboBox1.DisplayMember = "EMP_ID"
ComboBox1.SelectedIndex = -1
MyConnection.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
Me.Dispose()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If Trim(ComboBox1.Text) = Nothing Then
passTextbox.Enabled = False
Else
passTextbox.Enabled = True
passTextbox.Focus()
End If
End Sub
Private Sub ComboBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ComboBox1.Validating
If Trim(ComboBox1.Text) = Nothing Then
passTextbox.Enabled = False
Else
passTextbox.Enabled = True
passTextbox.Focus()
End If
End Sub
End Class
Thanks in advance.
-renzlo