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

    Error in displaying gridview through dropdownlist inasp.net using vb.net

    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")
    table1.Columns.Add("ReferenceNo")
    table1.Columns.Add("Title")
    table1.Columns.Add("Counterparty")
    table1.Columns.Add("OwnerDepartment")
    table1.Columns.Add("Status")
    table1.Columns.Add("CreatedBy")
    table1.Columns.Add("CreatedOn")
    table1.Columns.Add("link")
    table1.Rows.Clear()
    Dim conSQL As New SqlConnection(conStrDRS)
    conSQL.Open()
    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()
    adptSQL.Fill(myDataSet)
    conSQL.Close()
    gvDetails.DataSource = myDataSet.Tables(0) 'dvAlert
    gvDetails.DataBind()
    End Sub
    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
    BindGridView()
    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
    Hi,

    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.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #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.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #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