Friends please help me... I have Three text boxes 1.Bank 2.Acno 3.Name I am selecting record from database where Bank and Acno are =(txtbank.text and txtacno.text) If any record found, the focus should go to the third textbox-'Name' else message "Record not found" should be displayed.I tried the following code but no success.

CN.Open()
SQL = "SELECT *  from Receipts WHERE Bank='" & TxtBank.Text & "'" & "AND Acno='" & TxtAcno.Text & "'"
DA = New OleDb.OleDbDataAdapter(SQL, CN)
DA.Fill(DS, "Deposit")
If DS.Tables(0).Rows.Count = 0 Then
MsgBox("No Such Account")
Else
TxtName.Focus()
End If

TxtName.Text = "value" is how you assign to the TxtName text field

String value -Name of the a/c holder.It is retrieved from the table if "record is found". But does it affect the selection and record count? I think,txtName Will not come to the picture till the selection and record count is over.

There are so many experts in this forum,I know. Many times they have helped me much.But this time.. Being very new to VB.net my questions may be very silly.Don't disregard me. Please help please please.....

is there any error ? if yes what is it ?
what are you trying to do, just focus on name textbox or get the name value.

I want this ..if record exists name value should be reflected in txtname,simultaneously the focus should be shifted to txtName, if no record exists message "No such account" should be shown. On working my code neither name value is shown nor message is displayed, still the focus is shifted to txtName.

ok here's the code

        Dim cmd As OleDbCommand
        Dim dr As OleDbDataReader
        Try
            CN.Open()
            cmd = New OleDbCommand("SELECT *  from Receipts WHERE Bank='" & TxtBank.Text & "'" & "AND Acno='" & TxtAcno.Text & "'", CN)
            dr = cmd.ExecuteReader
            If dr.Read Then
                TxtName.Text = dr("Name")
                TxtName.Focus()
            Else
                MsgBox("No Such Account")
            End If
        Catch
        End Try
        dr.Close()
        cn.Close()

Ok Thank You.....I got it

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.