hello, im have problem with my code..im used access database, when i select combobox1, the textbox will appear data set as value member....but data not appear on textbox..someone can help me :)

this my code

Sub fillcombo()
        Dim acscmd As New OleDb.OleDbCommand
        acscmd.CommandText = strsql
        acscmd.Connection = acsconn
        acsdr = acscmd.ExecuteReader
        While (acsdr.Read())
        VehicleModel.Items.Add(acsdr("vehicleModel"))

        End While
        acscmd.Dispose()
        acsdr.Close()
    End Sub

Private Sub Schedule_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 Module1.connect()
        Me.fillcombo()

 Private Sub VehicleModel_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VehicleModel.SelectedIndexChanged
    strsql = "select * from tblVehicle where vehicleModel = ' " & VehicleModel.Text & "'"
    Dim acscmd As New OleDb.OleDbCommand
    acscmd.CommandText = strsql
    acscmd.Connection = acsconn
       acsdr = acscmd.ExecuteReader
       If (acsdr.Read() = True) Then
          VehiclePlat.Text = (acsdr("vehiclePlat"))
        End If

        acscmd.Dispose()
        acsdr.Close()
    End Sub

(in module)

Imports System.Data.OleDb

Module Module1
    Public acsconn As New OleDb.OleDbConnection
    Public acsdrr As OleDbDataReader
    Public strsql As String

    Sub connect()
        acsconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\D_S_S\SystemData.mdb"
        acsconn.Open()

    End Sub

End Module

Recommended Answers

All 4 Replies

Does your combo box selection result return only a single value???

Check what I have done...hope it helps u....set textbox AutoCompleteMode property to SuggestAppend

Imports System.Data.SqlClient

Public Class Form6

    Private Sub Form6_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'Open connection
        Dim strSQL As String = "SELECT Distinct ID,FirstName FROM Tablename"
        Dim da As New SqlDataAdapter(strSQL, Connection)
        Dim ds As New DataSet
        da.Fill(ds, "Tablename")
        With ComboBox1
            .DataSource = ds.Tables("Tablename")
            .DisplayMember = "FirstName"
            .ValueMember = "ID"
            .SelectedIndex = 0
        End With
        'Close connection
    End Sub


    Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        'Open connection
        Try
            Dim myCommand As SqlCommand
            myCommand = New SqlCommand("SELECT LastName FROM Tablename where FirstName='" + ComboBox1.Text + "'", Connection)
            Dim reader As SqlDataReader = myCommand.ExecuteReader
            While reader.Read()
                TextBox1.Text = reader("LastName")
            End While
            reader.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        'Close connection
    End Sub
End Class

Hope it helps u....

No..return other value...i mean when select vehicle model using combobox..at the textbox will appear vehicle plat info select from access database

that I understood...what I am asking is for one combox value will the text box have one value or many values???

did u check with the code I have posted??? give it a try....

well , if you just want to show the value in textbox related to the selected value of the combo then you can do like this ,

dim con as new sqlconnection("your connection string ")
con.open()
dim da as new sqldataadapter("select val1 , val2 from table ",con)
dim dt as new datatable
da.fill(dt)
combobox1.datasource = dt
combobox1.displaymember = "val1"
combobox1.valuemember = "val2"
con.close()

now this code will get the records from the db , use this code at the selected index change event of the combo box.

textbox1.text = combobox1.selectedvalue.tostring

the val2 will be display in the textbox.
as i am typed all this code right here so may be there is some spelling mistake , please check it by your own self ,

Regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.