title: how to bind specific sql colums in datagrid in vb.net?
body: <p>i am working on important project where i want to show specific columns from  sql database into datagridview when i search by itemcode in textbox. i have written a code but it is showing error. can somebody help me?</p>
  
  <p>my code is here</p>
  
  <pre><code>Public Class Form8
  
  Private Const constr As String = "server= PANKAJ\SQLEXPRESS; database = pankaj billing software; integrated security=true"
  Private bs As BindingSource = New BindingSource
  Private dt As DataTable = New DataTable
  Dim adapter As SqlDataAdapter
  Private cb As SqlCommandBuilder
  
  
  
  Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
      adapter = New SqlDataAdapter("select * from stockdata", constr)
      cb = New SqlCommandBuilder(adapter)
      adapter.Fill(dt)
      bs.DataSource = dt
      DataGridView1.DataSource = bs
  
  
      dt.Clear()
      adapter.SelectCommand.CommandText = "select * from customerdata where itemcode = @itemcode"
  
      adapter.SelectCommand.Parameters.AddWithValue("@itemcode", TextBox2.Text)
  
  
  
  
      'Set AutoGenerateColumns False
      DataGridView1.AutoGenerateColumns = False
  
          'Set Columns Count
          DataGridView1.ColumnCount = 3
  
          'Add Columns
          DataGridView1.Columns(0).Name = "stockId"
          DataGridView1.Columns(0).HeaderText = "Stock Id"
          DataGridView1.Columns(0).DataPropertyName = "stockID"
  
          DataGridView1.Columns(1).Name = "itemcode"
          DataGridView1.Columns(1).HeaderText = "Item Code"
          DataGridView1.Columns(1).DataPropertyName = "itemcode"
  
          DataGridView1.Columns(2).Name = "item"
          DataGridView1.Columns(2).HeaderText = "Item"
          DataGridView1.Columns(2).DataPropertyName = "item"
          DataGridView1.DataSource = dt
  
  
  
  
  End Sub
  </code></pre>