Question search amount less than or equal

navaneet31

New member
Joined
Sep 4, 2014
Messages
2
Programming Experience
Beginner
5d84ex.png


I made a tool for a realestate company i have done everything fine i got an issue with a search option.Let me explain.

In my database i have a column called quoted_amount, In that column each column contains like below.

5
6
9
10
44
556
78
23

What i need exactly is when i type a number 10 in search box it need to show all the rows that having quoted_amount less than or equal to 10 .

Thanks what code i suppose to write for it.

I have used the following search function for searching names and phonenumber ,But for number i failed to write code please help.

VB.NET:
 If typesearch.Text = "" Then            MsgBox("Please select type of search ")


        End If
        cnn = New OleDb.OleDbConnection
        cnn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Application.StartupPath & "\data.mdb"
        cnn.Open()
        Dim dt As New DataTable
        Dim ds As New DataSet
        ds.Tables.Add(dt)
        Dim da As New OleDbDataAdapter
        If typesearch.Text = "Contact Number" Then
            da = New OleDbDataAdapter("select * from Buyer_Data where Primary_Conno like '%" & searchbox.Text & "%'", cnn)
        ElseIf typesearch.Text = "Name" Then
            da = New OleDbDataAdapter("select * from Buyer_Data where cust_name like '%" & searchbox.Text & "%'", cnn)
        Else
            da = New OleDbDataAdapter("select * from Buyer_Data where Email_Address like '%" & searchbox.Text & "%'", cnn)
        End If


        da.Fill(dt)
        dgvData.DataSource = dt.DefaultView
        cnn.Close()
 
That's bad code I'm afraid because, by using string concatenation to insert values into SQL code, you open yourself up to several issues that could result in crashes or data loss. To learn the proper way, follow the Blog link in my signature below and check out my post on Parameters In ADO.NET.

As for the issue, the solution couldn't be simpler. The pattern for any WHERE condition is pretty much always the same: (Column Operator Value). In your case, the operator is going to be <= and the value is going to be the number. There will be no wildcards because they are only used with the LIKE operator and there will be no single quotes because they are only used for text values.
 
Also, don't do this:
cnn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Application.StartupPath & "\data.mdb"
Do this:
cnn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=|DataDirectory|\data.mdb"
That also allows you to put your connection string in the config file rather than hard-coding it, because it doesn't require code to be executed a run time.
 
That's bad code I'm afraid because, by using string concatenation to insert values into SQL code, you open yourself up to several issues that could result in crashes or data loss. To learn the proper way, follow the Blog link in my signature below and check out my post on Parameters In ADO.NET.

As for the issue, the solution couldn't be simpler. The pattern for any WHERE condition is pretty much always the same: (Column Operator Value). In your case, the operator is going to be <= and the value is going to be the number. There will be no wildcards because they are only used with the LIKE operator and there will be no single quotes because they are only used for text values.

I dont mind about the issues i will take care of them, I just want to know how to search numbers which are less than are equal to a particular value ,please give me the code thanku..
 
... maybe a little late - so for that apologies,

the normal sql statement that is used

Select [one or more Columns] from [the relevant tables] Where [Attribute You want to compare] <= [value that is entered]
 

Latest posts

Back
Top