Question show data in textbox when combobox are selected

ladivito

Member
Joined
Mar 9, 2015
Messages
8
Programming Experience
Beginner
Dear All,

im using vs 2013 and ms access 2010 (*.accdb)
i had some problem on this code below, basically the function i want when the combobox are selected then it will search the data in the database then show at the textbox. Thanks for helping :)

The Error as below :
Untitled.png


The Code as below :


Dim con2 As New OleDb.OleDbConnection
Dim dbProvider2 As String
Dim dbSource2 As String
Dim ds2 As New DataSet
Dim da2 As OleDb.OleDbDataAdapter
Dim sql2 As String

Private Sub enamecombo_SelectedIndexChanged(sender As Object, e As EventArgs) Handles enamecombo.SelectedIndexChanged


dbProvider2 = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
dbSource2 = "Data Source = |DataDirectory|\empdb.accdb"


con2.ConnectionString = dbProvider2 & dbSource2


Try
eictextbox.Clear()


con2.Open()
sql2 = "Select eic from tblemp where ename = '" & enamecombo.Text & "' "
da2 = New OleDb.OleDbDataAdapter(sql2, con2)
da2.Fill(ds2, "tblemp")


Dim command2 As New System.Data.OleDb.OleDbCommand(sql2, con2)
Dim reader2 As System.Data.OleDb.OleDbDataReader = command2.ExecuteReader()


While reader2.Read()
eictextbox.Text = reader2.GetString("eic") <----- the eic at the database is as text
End While


reader2.Close()
con2.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try


End Sub
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,577
Location
Sydney, Australia
Programming Experience
10+
You can't just make up any method you want and call it. That method has to actually exist. Have you read the documentation for the OleDbDataReader.GetString method? The Help menu is there on your VS menu for a reason. If you need help, use the Help menu first. If you had done that then you'd already know what the issue is. If you can't find what you need in the MSDN documentation then by all means post here or on other forums but always use the Help menu first.
 

ladivito

Member
Joined
Mar 9, 2015
Messages
8
Programming Experience
Beginner
You can't just make up any method you want and call it. That method has to actually exist. Have you read the documentation for the OleDbDataReader.GetString method? The Help menu is there on your VS menu for a reason. If you need help, use the Help menu first. If you had done that then you'd already know what the issue is. If you can't find what you need in the MSDN documentation then by all means post here or on other forums but always use the Help menu first.


Hi,

i search the msdn but just dont understand the simple explanation at there. TQ
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,559
Location
Norway
Programming Experience
10+
Top Bottom