Click here to Skip to main content
15,880,427 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
My Code is that but in dont know display that error
VB
Dim SampleOrder As String = Nothing
        Dim Requester As String = Nothing
        Dim ProjectNumber As String = Nothing
        Dim CostCenter As String = Nothing
        Dim PersonInvoiced As String = Nothing
        Dim SelectQuery As String = "SELECT [OrderID], [DVMOrderNumber], [Requester], [ProjectNumber], [CostCenter], [CostResponsable], [CostCategory], [TotalSamples], [OrderDescription], [FinalCustomerAddress], [TargetDate], [AssemblyPlannedDate], [LogisticsResponsable], [ShippingMode], [ShippingAddress], [Urgent], [HasBOM], [HazardousMaterial], [ExpressShipment], [HasSerialComponents], [PrototypeComponents], [OrderType] FROM [Orders_Header]"
        Dim WhereQuery As String = Nothing

        Requester = BOX_Requester1.Text
        Requester = Find.Find2(Requester)

        If Requester <> Nothing Then
            WhereQuery = WhereQuery & " AND Requester LIKE '" & Requester & "'"
        End If

  

        Dim myQuery As String = SelectQuery & WhereQuery
        SqlDataSource2.SelectCommand = myQuery
        GridView1.DataSourceID = "SqlDataSource2"
        GridView1.DataBind()

        If GridView1.Rows.Count = 0 Then
            LBL_Error.Visible = True
            LBL_Error.Text = "I have not found any results by your search!"
            LBL_Status.Text = String.Empty
        Else
            LBL_Status.Visible = True
            LBL_Status.Text = "Dates have been loaded! Found " + Convert.ToString(GridView1.Rows.Count) + " rows."
            LBL_Error.Text = String.Empty
        End If
Posted
Updated 1-Sep-15 0:55am
v2

WhereQuery is Nothing initially. When you append a condition to the query you need a WHERE first. Here, you are using an AND
1) without a WHERE
2) without any other where filter in the query

This might solve your problem
SQL
If Requester <> Nothing Then
 IF WhereQuery <> Nothing Then
    WhereQuery = WhereQuery & " AND Requester LIKE '" & Requester & "'"
 Else
    WhereQuery = " WHERE Requester LIKE '" & Requester & "'"
 End If
End If
 
Share this answer
 
Comments
Member 11950310 1-Sep-15 7:23am    
Thaaanks alot!
MoraruVladut 2-Sep-15 2:33am    
Work, thanks
Change this line
VB
Dim WhereQuery As String = Nothing

to
VB
Dim WhereQuery As String = " WHERE 1=1"


Hope it helps :)
 
Share this answer
 
Comments
Member 11950310 1-Sep-15 7:23am    
Thhhhaaanks alot!
Suvendu Shekhar Giri 2-Sep-15 4:11am    
Glad to know that it helped. Please mark those solutions as answer those helped you in solving the problem so that others can refer.

:)
MoraruVladut 2-Sep-15 2:33am    
Work, thanks

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