Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Setting DisplayMember & ValueMember with DataTable

Setting DisplayMember & ValueMember with DataTable

Scheduled Pinned Locked Moved .NET (Core and Framework)
databasehelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    massaslayer
    wrote on last edited by
    #1

    Public Sub s_zoekEntiteit(ByVal i_entiteit As String)

        Dim sqlStr As String = "zoekEntiteit '" & i\_entiteit & "'"
        Dim dataAdapter = New SqlDataAdapter(sqlStr, m\_constring)
        Dim commandBuilder As New SqlCommandBuilder(dataAdapter)
        Dim DataGridTable As New DataTable()
    
        dataAdapter.Fill(DataGridTable)
        
        Form5.ListBox1.DataSource = DataGridTable
        Form5.ListBox1.DisplayMember = i\_entiteit
        Form5.ListBox1.ValueMember = i\_entiteit
    
    End Sub
    

    The Stored Procedure:

    CREATE PROCEDURE zoekEntiteit (@tmpEntiteit nvarchar(40))AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    SELECT @tmpEntiteit FROM tblProduct;
        --'ByVal i\_prodid As String, ByVal i\_prodnaam As String, ByVal i\_prodomschrijving As String, 
        --'ByVal i\_prodprijs As Int16, ByVal i\_prodinstock As String)
    

    END

    The RESULT if @tmpEntiteit would be ProdID : Image to Result What is wrong here I keep getting an error on ' Form5.ListBox1.ValueMember = i_entiteit' the following error : Can't bind to the new DisplayMember. Paramater newDisplayMember

    A 1 Reply Last reply
    0
    • M massaslayer

      Public Sub s_zoekEntiteit(ByVal i_entiteit As String)

          Dim sqlStr As String = "zoekEntiteit '" & i\_entiteit & "'"
          Dim dataAdapter = New SqlDataAdapter(sqlStr, m\_constring)
          Dim commandBuilder As New SqlCommandBuilder(dataAdapter)
          Dim DataGridTable As New DataTable()
      
          dataAdapter.Fill(DataGridTable)
          
          Form5.ListBox1.DataSource = DataGridTable
          Form5.ListBox1.DisplayMember = i\_entiteit
          Form5.ListBox1.ValueMember = i\_entiteit
      
      End Sub
      

      The Stored Procedure:

      CREATE PROCEDURE zoekEntiteit (@tmpEntiteit nvarchar(40))AS
      BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

      SELECT @tmpEntiteit FROM tblProduct;
          --'ByVal i\_prodid As String, ByVal i\_prodnaam As String, ByVal i\_prodomschrijving As String, 
          --'ByVal i\_prodprijs As Int16, ByVal i\_prodinstock As String)
      

      END

      The RESULT if @tmpEntiteit would be ProdID : Image to Result What is wrong here I keep getting an error on ' Form5.ListBox1.ValueMember = i_entiteit' the following error : Can't bind to the new DisplayMember. Paramater newDisplayMember

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      I expect its because you don't have a column called i_entiteit in your datatable - your stored procedure returns a column name of (no column name), but as it simply returns the value you pass to it anyway its pointless.

      Bob Ashfield Consultants Ltd

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups