Search Code VB.NET & SQL

How to search using VB.NET in Sql Data

Page 1 of 1

3 Replies - 17741 Views - Last Post: 08 January 2011 - 11:35 PM Rate Topic: -----

#1 e.alnajjar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-December 10

Search Code VB.NET & SQL

Posted 06 January 2011 - 01:27 AM

I have my code for moving to records in sql data base but i need to know how to search specific record by the value of one field like Category ID in my example : my code as follow

[code

Private Sub CmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdNext.Click


On Error Resume Next

If cr = Tot - 1 Then
cr = 0
Else
cr += 1
End If

'display next records

Tot = ds.Tables("Categories").Rows.Count()

txtCatID.Text = ds.Tables("Categories").Rows(cr).Item("CategoryID")
txtCatName.Text = ds.Tables("Categories").Rows(cr).Item("CategoryName")
txtDes.Text = ds.Tables("Categories").Rows.Item(cr)("CatDescription")




End Sub

Private Sub CmdPre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdPre.Click


On Error Resume Next

'Prev button

If cr = 0 Then

cr = Tot - 1

Else

cr -= 1

End If

'display next records

Tot = ds.Tables("Categories").Rows.Count()



txtCatID.Text = ds.Tables("Categories").Rows(cr).Item("CategoryID")
txtCatName.Text = ds.Tables("Categories").Rows(cr).Item("CategoryName")
txtDes.Text = ds.Tables("Categories").Rows.Item(cr)("CatDescription")




End Sub

Private Sub CmdLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdLast.Click


Tot = ds.Tables("Categories").Rows.Count()

cr = Tot - 1

txtCatID.Text = ds.Tables("Categories").Rows(cr).Item("CategoryID")
txtCatName.Text = ds.Tables("Categories").Rows(cr).Item("CategoryName")
txtDes.Text = ds.Tables("Categories").Rows.Item(cr)("CatDescription")


End Sub

Private Sub CmdFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdFirst.Click


txtCatID.Text = ds.Tables("Categories").Rows(0).Item("CategoryID")
txtCatName.Text = ds.Tables("Categories").Rows(0).Item("CategoryName")
txtDes.Text = ds.Tables("Categories").Rows.Item(0)("CatDescription")


End Sub

Private Sub CmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdClose.Click

Me.Close()

End Sub

code]

Is This A Good Question/Topic? 0
  • +

Replies To: Search Code VB.NET & SQL

#2 e.alnajjar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-December 10

Re: Search Code VB.NET & SQL

Posted 06 January 2011 - 01:34 AM

Sorry the code i have don is


 Private Sub CmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdNext.Click


        On Error Resume Next

        If cr = Tot - 1 Then
            cr = 0
        Else
            cr += 1
        End If

        'display next records

        Tot = ds.Tables("Categories").Rows.Count()

        txtCatID.Text = ds.Tables("Categories").Rows(cr).Item("CategoryID")
        txtCatName.Text = ds.Tables("Categories").Rows(cr).Item("CategoryName")
        txtDes.Text = ds.Tables("Categories").Rows.Item(cr)("CatDescription")



        
    End Sub

    Private Sub CmdPre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdPre.Click


        On Error Resume Next

        'Prev button

        If cr = 0 Then

            cr = Tot - 1

        Else

            cr -= 1

        End If

        'display next records

        Tot = ds.Tables("Categories").Rows.Count()



        txtCatID.Text = ds.Tables("Categories").Rows(cr).Item("CategoryID")
        txtCatName.Text = ds.Tables("Categories").Rows(cr).Item("CategoryName")
        txtDes.Text = ds.Tables("Categories").Rows.Item(cr)("CatDescription")




    End Sub

    Private Sub CmdLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdLast.Click


        Tot = ds.Tables("Categories").Rows.Count()

        cr = Tot - 1

        txtCatID.Text = ds.Tables("Categories").Rows(cr).Item("CategoryID")
        txtCatName.Text = ds.Tables("Categories").Rows(cr).Item("CategoryName")
        txtDes.Text = ds.Tables("Categories").Rows.Item(cr)("CatDescription")


    End Sub

    Private Sub CmdFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdFirst.Click

        
        txtCatID.Text = ds.Tables("Categories").Rows(0).Item("CategoryID")
        txtCatName.Text = ds.Tables("Categories").Rows(0).Item("CategoryName")
        txtDes.Text = ds.Tables("Categories").Rows.Item(0)("CatDescription")


    End Sub

    Private Sub CmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdClose.Click

        Me.Close()

    End Sub



Was This Post Helpful? 0
  • +
  • -

#3 germalto  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 12-May 10

Re: Search Code VB.NET & SQL

Posted 07 January 2011 - 04:24 PM

okay insted of all that I recommend using a query

assuming the field you want to search= Username you should add this into a new query using the query builder

Username LIKE @Username + N'%'


then (assuming you have called the query fillbycustomer and txt search is the text you want to search add this into the button you want to click search on

Me.TblCustomerProfileTableAdapter.FillBycustomer(Me.DatabaseDataSet.tblCustomer, txtSearch.Text)


hope this helps please ask if you have any queries !!
Was This Post Helpful? 0
  • +
  • -

#4 e.alnajjar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-December 10

Re: Search Code VB.NET & SQL

Posted 08 January 2011 - 11:35 PM

Can i get small example , i am new in VB.NET i tried but i cold't get the result .
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1