2 Replies - 1251 Views - Last Post: 03 April 2013 - 06:43 PM

#1 Adqusit  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 143
  • Joined: 02-March 13

how to load only single record into DGV

Posted 03 April 2013 - 09:14 AM

HI. I have a helping form, which appears on the leave event of the textbox of main form (SaleInfo). When this form is loaded so the Prod_Name from ProdInfo table is loaded into Combobox (where, combobox is set to AutoComplete).

On the form, I have DGV, Combobox and a Button, on which i have the following Query:

Dim selProd As String = "select * from ProdInfo where Prod_Name like '%" & ComboBox1.Text & "%'"


I want to load only that product into a DataGridView, which is selected in Combobox. But when i press the button so it displays the entire table values. Please tell me that what is wrong with this like query.

Is This A Good Question/Topic? 0
  • +

Replies To: how to load only single record into DGV

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2890
  • View blog
  • Posts: 9,597
  • Joined: 12-December 12

Re: how to load only single record into DGV

Posted 03 April 2013 - 11:19 AM

You are using like rather than =, so it will find all product-names that contain the sequence of letters in your combobox.
Was This Post Helpful? 0
  • +
  • -

#3 Adqusit  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 143
  • Joined: 02-March 13

Re: how to load only single record into DGV

Posted 03 April 2013 - 06:43 PM

Very well. I first used the simple query with = '"& combobox1.text & "'", but this is not working either. Please tell me what to do now?

This is my code on the form load event:
  dsSql.Clear()

        Dim selProd As String = "select * from ProdInfo"
        Dim cmSql As New SqlCommand(selProd, cnSql)
        cmSql.CommandType = CommandType.Text
        daSql.SelectCommand = cmSql

        daSql.Fill(dsSql, "ProdInfo")

        'dgvSalesPicker.DataSource = dsSql2
        'dgvSalesPicker.DataMember = "ProdInfo"

        Dim a As Integer
        For a = 0 To dsSql.Tables("ProdInfo").Rows.Count - 1
            ComboBox1.Items.Add(dsSql.Tables("ProdInfo").Rows(a).Item(1))
        Next



And This is my button click event code:

    Try
            If ComboBox1.Text = "" Then
                MessageBox.Show("At least one value must be mention in textbox", "SellingMS", MessageBoxButtons.OK)
                ComboBox1.Focus()
                Exit Sub
            Else

  Dim selProd As String = "select * from ProdInfo where Prod_Name like '%" & ComboBox1.Text & "%'"
                Dim cmdSql As New SqlCommand(selProd, cnSql)
                cmdSql.CommandType = CommandType.Text
                daSql.SelectCommand = cmdSql

                daSql.Fill(dsSql, "ProdInfo")

                dgvSalesPicker.DataSource = dsSql
                dgvSalesPicker.DataMember = "ProdInfo"
End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1