Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
datagrid named grdSearch
Function called is name sqlSelect
My code displays everything when the form first loads. but when i click search i want only the london people of the database to show. however, my datagrid doesnt update

VB
 Function sqlSelect(ByVal sqlString As String)
        da = New OleDbDataAdapter(sqlString, con)
        da.Fill(ds, "Results")
        Return ds
    End Function

Imports System.Data.SqlClient
Public Class frmSearch
    Dim db As New clsDBConnector
    Dim ds As New DataSet
    Private Sub frmSearch_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        db.connect()

        Dim sqlselect As String
        Dim ds As New DataSet

        sqlselect = "SELECT * FROM tbltest"
        ds = db.sqlSelect(sqlselect)
        grdSearch.DataSource = ds.Tables(0)
    End Sub

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click

        Dim sqlselect As String
        Dim ds As New DataSet

        sqlselect = "SELECT * FROM tbltest WHERE City= 'London'"
        ds = db.sqlSelect(sqlselect)
        grdSearch.DataSource = ds.Tables(0)

    End Sub
End Class


thanks
Posted
Updated 9-Sep-14 2:37am
v2
Comments
member33 9-Sep-14 9:02am    
need to wrap your initial load in not ispostback

i had to clear my dataset.

VB
Imports System.Data.SqlClient
Public Class frmSearch
    Dim db As New clsDBConnector
    Dim ds As New DataSet
    Private Sub frmSearch_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        db.connect()
        Dim sqlselect As String

        sqlselect = "SELECT * FROM tbltest"
        ds = db.sqlSelect(sqlselect)
        grdSearch.DataSource = ds.Tables(0)
    End Sub

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        Dim sqlselect As String
        ds.Clear()
        sqlselect = "SELECT * FROM tbltest WHERE City= 'London'"
        ds = db.sqlSelect(sqlselect)
        grdSearch.DataSource = ds.Tables(0)
    End Sub
End Class
 
Share this answer
 
Also i am not sure whether we need to provide return type for the SqlSelect function.

Please check whether the dataset returns any data.
 
Share this answer
 
Comments
MrSuperT 9-Sep-14 10:23am    
yes first time it loads. data is returned. when the button btnSearch is clicked nothing happens
Try changing the frmSearch_Load in the following manner

VB
Private Sub frmSearch_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        db.connect()

        Dim sqlselect As String
        Dim ds As New DataSet
        If Not Page.IsPostBack Then
           sqlselect = "SELECT * FROM tbltest"
           ds = db.sqlSelect(sqlselect)
           grdSearch.DataSource = ds.Tables(0)
        End If
    End Sub


Hope the above code helps.
 
Share this answer
 
Comments
MrSuperT 11-Sep-14 6:11am    
when i add this a get an error message saying "Page is not declared" so i replaced Page with my form name but then it says tht "IsPostBack is not a member of..."
ChauhanAjay 11-Sep-14 6:19am    
are you using windows forms or web forms
MrSuperT 11-Sep-14 6:21am    
im using windows form

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900