Example : How to search the duplicate record present in the database or not.
(Write/put connectivity code here, first.)

Private Sub BtnSave_Click(sender As Object, e As EventArgs) Handles BtnSave.Click

   Dim p As String = ""
   Dim u As String = ""

   cn.Open()
      cm.CommandText = "select category,centercode from newcenter"
      rdr = cm.ExecuteReader(CommandBehavior.SequentialAccess)
 
      While (rdr.Read())
         u = rdr("category").ToString.Trim()
         p = rdr("centercode").ToString.Trim()

         If CmbCat.Text = u And CmbCc.Text = p Then        
            MsgBox("Similar CATEGORY and CENTER CODE Already Saved, Use Another")
            CmbCc.Text = ""
            CmbCc.Focus()
            cn.Close()
            Exit Sub
          End If
      End While
   cn.Close()
End Sub

NB : Here 'CmbCat.Text' & 'CmbCc.Text' are two text box for matching two values.
Example : How to search specific data/record from database & display/put those into                      various vb controls or Text box etc. 
( Write Connectivity code first here )

Private Sub BtnSearch_Click(sender As Object, e As EventArgs) Handles BtnSearch.Click
    Dim rdb1 As String
    Dim combo1 As String
    Dim chbox1 As String
    Dim chbox2 As String

    cn.Open()
        cm.CommandText = "select * from DatabaseTable where TxtSerial5 = '" + TxtSerial.Text + "'"
        rdr = cm.ExecuteReader()
        While (rdr.Read())
            TxtName.Text = rdr("TxtName5").ToString
            DateTimePickerDob.Text = rdr("DtDob5").ToString
            NumMobile.Text = rdr("TxtMobile5").ToString

            rdb1 = rdr("RdbGender5").ToString
            If rdb1.Trim().ToString = "Male" Then
                RdbGender1.Checked = True
            ElseIf rdb1.ToString = "Female" Then
                RdbGender2.Checked = True
            End If

            chbox1 = rdr("ChkMatric5").ToString            
            If chbox1.Trim().ToString = "Matric" Then
                ChkMatric.Checked = True
            End If
            chbox2 = rdr("ChkInter5").ToString            
            If chbox2.Trim().ToString = "Inter" Then
                ChkInter.Checked = True
            End If

            combo1 = rdr("CmbNational5").ToString
            Me.CmbNational.SelectedItem = combo1.Trim()            

            TxtUname.Text = rdr("TxtUname5")
            TxtPass.Text = rdr("TxtPass5").ToString
            RtbAddress.Text = rdr("RtbAddress5").ToString
        End While
        cn.Close()
    End Sub
Example : How to search specific data/record by merging two tables of sql server database. 
Example : How to search specific data/record by merging three tables of sql server database. 

 1,309 total views,  3 views today

Categories: VB .Net

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.