Click here to Skip to main content
15,895,784 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 1 table name item where columns are broker_id,name,auction_name,date,year,lot_no.

Now i have put all these columns in combo box collection.

Now i want as the user clicks on any one of the columns in combo box.

e.g lot_no

then the user will type any particular lotno in textbox and click on search button,then it will display in grid view whether that particular lotno is there in database or not.

Please can anyone help me with code?

or can any one suggest me any other good or interactive method to use for search.

Can i use ajax here?

Mine project is windows application and i am using visual studio ultimate 2010 and sql server 2012.

Please kindly help.


Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
       Dim str As String = ("Data Source=.\INSTANCE;initial catalog=example;user=sa;password=gariahat")

       Dim con As New SqlConnection(str)

       Dim cmd As New SqlCommand("select * from item where broker_id like '%" + Trim(TextBox1.Text) + "%'", con)

       Dim da As New SqlDataAdapter(cmd)

       Dim ds As New DataSet()

       If (da.Fill(ds, "item")) Then

           ItemDataGridView.DataSource = ds.Tables(0)


           MessageBox.Show("match found")

       Else

           MessageBox.Show("match not found")

       End If

   End Sub
Posted
Updated 3-Sep-13 20:15pm
v2
Comments
sudeshna from bangkok 4-Sep-13 4:01am    
Imports System.Data.SqlClient
Imports System.Data

Public Class Form6
Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial catalog=example;user=sa;password=gariahat")
Dim da As New SqlDataAdapter
Dim cmd As New SqlCommand
'Dim dr As New SqlDataReader
Dim dt1 As DataTable
Dim ds As New DataSet

Private Sub ItemBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles ItemBindingNavigatorSaveItem.Click
Me.Validate()
Me.ItemBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.ExampleDataSet)

End Sub

Private Sub Form6_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'ExampleDataSet.item' table. You can move, or remove it, as needed.
'Me.ItemTableAdapter.Fill(Me.ExampleDataSet.item)

End Sub


Private Sub search()
Dim str As String = ("Data Source=.\INSTANCE;initial catalog=example;user=sa;password=gariahat")

Dim con As New SqlConnection(str)
If ComboBox1.SelectedIndex = 0 Then
Dim cmd As New SqlCommand("select * from item where 'broker_id' like '%" + Trim(TextBox1.Text) + "%'", con)



Dim da As New SqlDataAdapter(cmd)

Dim ds As New DataSet()

If (da.Fill(ds, "item")) Then

ItemDataGridView.DataSource = ds.Tables(0)


MessageBox.Show("match found")

Else

MessageBox.Show("match not found")

End If
ElseIf ComboBox1.SelectedIndex = 1 Then
Dim cmd As New SqlCommand("select * from item where 'name' like '%" + Trim(TextBox1.Text) + "%'", con)



Dim da As New SqlDataAdapter(cmd)

Dim ds As New DataSet()

If (da.Fill(ds, "item")) Then

ItemDataGridView.DataSource = ds.Tables(0)


MessageBox.Show("match found")

Else

MessageBox.Show("match not found")

End If
End If


End Sub

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
search()
End Sub

End Class
sudeshna from bangkok 4-Sep-13 4:01am    
This is my code,I have done some modifications after checking these links,but still its not working.Can anyone help me plz

You can't expect exactly same things because everyone works in particular domain.Check these 2,you will get an idea:
VB.NET - Search function using Textbox and Combo Box[^]
search database using combo and text box[^]

EDIT:
Do something like:
VB
Dim SearchText As String = TextBox1.Text 
Dim cmd As New SqlCommand("SELECT * FROM item WHERE broker_id Like '%" & SearchText & "%' ", con) 

and edit your next query also according to this.
 
Share this answer
 
v2
Comments
sudeshna from bangkok 4-Sep-13 3:32am    
Can you give some other code please which is written in vb.net, not in C#
sudeshna from bangkok 4-Sep-13 3:37am    
This code is not working in vb.net
ridoy 4-Sep-13 3:42am    
really?! those are written in vb,not c#. And as i said you earlier, you will not find exactly same as you want,you need to see the solutions and implement on your own.
sudeshna from bangkok 4-Sep-13 4:06am    
Ok,but i am new to this,so cant implement it correctly.I have reposted my code,can you help me as to where is wrong with my code.
Its always going to the else part and showing match not found
sudeshna from bangkok 4-Sep-13 4:48am    
Can you help me how to modify this code?
Imports System.Data.SqlClient
Imports System.Data

Public Class Form6
    Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial catalog=example;user=sa;password=gariahat")
    Dim da As New SqlDataAdapter
    Dim cmd As New SqlCommand
    'Dim dr As New SqlDataReader
    Dim dt1 As DataTable
    Dim ds As New DataSet

    Private Sub ItemBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles ItemBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.ItemBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.ExampleDataSet)

    End Sub

    Private Sub Form6_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'ExampleDataSet.item' table. You can move, or remove it, as needed.
        'Me.ItemTableAdapter.Fill(Me.ExampleDataSet.item)

    End Sub


    Private Sub search()
        Dim str As String = ("Data Source=.\INSTANCE;initial catalog=example;user=sa;password=gariahat")

        Dim con As New SqlConnection(str)
        If ComboBox1.SelectedIndex = 0 Then
            Dim searchtext As String = TextBox1.Text
            Dim cmd As New SqlCommand("select  * from item where broker_id like '%" & searchtext & "%'", con)
            Dim da As New SqlDataAdapter(cmd)

            Dim ds As New DataSet()

            If (da.Fill(ds, "item")) Then

                ItemDataGridView.DataSource = ds.Tables(0)


                MessageBox.Show("match found")

            Else

                MessageBox.Show("match not found")

            End If
        ElseIf ComboBox1.SelectedIndex = 1 Then
            Dim searchtext As String = TextBox1.Text
            Dim cmd As New SqlCommand("select  * from item where name like '%" & searchtext & "%' order by broker_id", con)
            Dim da As New SqlDataAdapter(cmd)

            Dim ds As New DataSet()

            If (da.Fill(ds, "item")) Then

                ItemDataGridView.DataSource = ds.Tables(0)


                MessageBox.Show("match found")

            Else

                MessageBox.Show("match not found")

            End If
        ElseIf ComboBox1.SelectedIndex = 2 Then
            Dim searchtext As String = TextBox1.Text
            Dim cmd As New SqlCommand("select  * from item where lot_no like '%" & searchtext & "%'order by broker_id", con)
            Dim da As New SqlDataAdapter(cmd)

            Dim ds As New DataSet()

            If (da.Fill(ds, "item")) Then

                ItemDataGridView.DataSource = ds.Tables(0)


                MessageBox.Show("match found")

            Else

                MessageBox.Show("match not found")

            End If
        ElseIf ComboBox1.SelectedIndex = 3 Then
            Dim searchtext As String = TextBox1.Text
            Dim cmd As New SqlCommand("select  * from item where place like '%" & searchtext & "%' order by broker_id", con)
            Dim da As New SqlDataAdapter(cmd)

            Dim ds As New DataSet()

            If (da.Fill(ds, "item")) Then

                ItemDataGridView.DataSource = ds.Tables(0)


                MessageBox.Show("match found")

            Else

                MessageBox.Show("match not found")

            End If
        ElseIf ComboBox1.SelectedIndex = 4 Then
            Dim searchtext As String = TextBox1.Text
            Dim cmd As New SqlCommand("select  * from item where year like '%" & searchtext & "%' order by broker_id", con)
            Dim da As New SqlDataAdapter(cmd)

            Dim ds As New DataSet()

            If (da.Fill(ds, "item")) Then

                ItemDataGridView.DataSource = ds.Tables(0)


                MessageBox.Show("match found")

            Else

                MessageBox.Show("match not found")

            End If
        End If

    End Sub
    
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        search()
    End Sub

End Class
 
Share this answer
 

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