i want to auto bind data to my textbox after user click the textbox and i already make it!!
but my problem is, after i click the textbox again, it still same as the first click!!!
HELP ME!!!!

the same thing in the first click, this is my code....

    Private Sub txtNama_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtNama.MouseClick
        Dim ds As New DataSet
        Dim dt As New DataTable
        ds.Tables.Add(dt)
        Dim a As String = "SELECT NAMA, KURSUS FROM DAFTARPELAJAR WHERE NDP = @NDP"
        Dim b As New OleDbDataAdapter(acscmd)

        acscmd.CommandText = a
        With acscmd.Parameters
            .AddWithValue("@NDP", txtNDP.Text)
        End With
        b.Fill(dt)
        txtNama.Text = dt.Rows(0).Item(0)
        txtKursus.Text = dt.Rows(0).Item(1)
    End Sub

this code only run in the first click, i dont know why.

Your first problem is that you have to use ? for parameters when you use OleDb so your query should be

Dim a As String = "SELECT NAMA, KURSUS FROM DAFTARPELAJAR WHERE NDP = ?"

When I try the code on my database (with the corrected query) it works just fine. If I type a new value in txtNDP and click on txtNama then the control gets updated. Incidentally, what you are doing is not called binding. You are just fetching a value and populating the textbox manually. You might as well just use a datareader.

oh, ok....thank for you information about populating the the textbox, i already try the query that you give, but after i run the code it will show error on line b.fill(dt) = Data type mismatch in criteria expression. That why im using parameter to solve the error.
i also try to clear the txtnama.text but when new ndp is filled and click at txtnama it still show the 1st clicked data.
its like the event running on 1st click only.

nvm!! i solve the problem, adding this code at the last line!

acscmd.Parameters.Clear()

Thanks Reverend Jim!!

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.