You must Sign In to post a response.
  • Category: ASP.NET

    Error in displaying gridview through dropdownlist using

    Hi I changed my code it shows error when displaying through dropdown list it shows "Incorrect syntax near AND" can anybody help me to fix this issue
    Private Sub BindGridView()
    Dim filter As String = ""
    If ddlOwnerDepartment.SelectedValue <> "" Then
    filter = filter & " AND OwnerDepartment ='" & ddlOwnerDepartment.SelectedValue & "'"
    End If
    Dim table1 As DataTable = New DataTable("Details")
    Dim conSQL As New SqlConnection(conStrDRS)
    Dim cmdSQL As SqlCommand = New SqlCommand("SELECT Title, ReferenceNo,OwnerDepartment,CreatedBy,CreatedOn,Status,Counterparty " & _
    " FROM [dbo].[Registration]" & filter)

    cmdSQL.Connection = conSQL
    Dim adptSQL As New SqlClient.SqlDataAdapter(cmdSQL)
    Dim myDataSet As New DataSet()
    gvDetails.DataSource = myDataSet.Tables(0) 'dvAlert
    End Sub
    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
    End Sub
  • #763960
    1. Have one text box
    2. In the button click get the value from the text box
    3. Send that value as parameter to BindGridView()
    4. In the SQL Query compare textbox value with whatever the fields you want

    Following is the sample query to do the serach.

    SELECT Title, ReferenceNo,OwnerDepartment,CreatedBy,CreatedOn,Status,Counterparty where Status=SearchText or OwnerDepartment = SearchText ....

    By Nathan
    Direction is important than speed

  • #763966

    Control is not an matter, when filter the record but the only one concern is whether that control passes exact value for filter or not.

    If the control pass exact value then SQL query will taking care for filter the data and display.

    Select * from tablename
    Where conditions

    In above query conditions are up to your requirement.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #763969
    Hi Naveen so finally you telling change in sql is the code ok??

  • #763974
    Hi Nathan I cant use search button I want to display data when click button

  • #763993
    Hai Nagendra,
    Check the code which you wrote:

    Dim filter As String = ""
    If ddlOwnerDepartment.SelectedValue <> "" Then
    filter = filter & " AND OwnerDepartment ='" & ddlOwnerDepartment.SelectedValue & "'"
    End If

    Here at the initial, we should not add the 'AND' and due to that it is getting problem.
    You can try with :

    filter = filter & " OwnerDepartment ='" & ddlOwnerDepartment.SelectedValue & "'"

    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #764002
    Hi pawan I changed my code and tried but no change cannot display through dropdown list. is there any option

  • Sign In to post your comments