Advanced Help for Combo box Needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jean Christophe Avard

    #1

    Advanced Help for Combo box Needed

    Hi! I'm designing an application that produces invoices. I have a combobox
    that is populated with the Name of every client in the database. What I
    would like to do is to have the combobox to display the name, and to have
    the value set to the ID of the record...

    Like in HTML where you have something like: <option value="ID_NUMBE R(primary
    key)">CLIENT_NA ME</option>

    so, let's say the user selects "Client #2" in the combo box, then I would be
    able to call the address of this client using the ID... SELECT * FROM
    tbl_clients WHERE id_client = bombobox.select edValue ...

    I don't know if I'm making myself clear, I will be around, so ask anything
    if I'm not enough clear. Thank y'all, this really apprecioated!

    Jean Christophe Avard!


  • Kerry Moorman

    #2
    RE: Advanced Help for Combo box Needed

    Jean Christophe Avard,

    Retrieve the client name and ID from the database and store the data in a
    datatable.

    Assign the datatable to the combobox'x DataSource.

    Assign the client name to the combobox's DisplayMember.

    Assign the client ID to the combobox's ValueMember.

    In the combobox'x SelectedIndexCh anged event, retrieve the ID from the
    combobox's SelectedValue property.

    Kerry Moorman




    "Jean Christophe Avard" wrote:
    [color=blue]
    > Hi! I'm designing an application that produces invoices. I have a combobox
    > that is populated with the Name of every client in the database. What I
    > would like to do is to have the combobox to display the name, and to have
    > the value set to the ID of the record...
    >
    > Like in HTML where you have something like: <option value="ID_NUMBE R(primary
    > key)">CLIENT_NA ME</option>
    >
    > so, let's say the user selects "Client #2" in the combo box, then I would be
    > able to call the address of this client using the ID... SELECT * FROM
    > tbl_clients WHERE id_client = bombobox.select edValue ...
    >
    > I don't know if I'm making myself clear, I will be around, so ask anything
    > if I'm not enough clear. Thank y'all, this really apprecioated!
    >
    > Jean Christophe Avard!
    >
    >
    >[/color]

    Comment

    • Jean Christophe Avard

      #3
      Re: Advanced Help for Combo box Needed

      Thank you man, but I have another q7uestion... Why do I get an error with
      this:

      sql = "SELECT * FROM tbl_clients WHERE id_client= " +
      cboxClient.Sele ctedValue

      I also tried

      sql = "SELECT * FROM tbl_clients WHERE id_client= " +
      cboxClient.Sele ctedValue.toStr ing()

      And it always give me an error

      "An unhandled exception of type 'System.Invalid CastException' occurred in
      microsoft.visua lbasic.dll

      Additional information: Operator is not valid for string "SELECT * FROM
      tbl_clients WHERE " and type 'DataRowView'."

      What is the way to go!?

      "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.com> wrote in message
      news:<8DD4FCC2-ECF6-411E-9897-301350DD54D9@mi crosoft.com>...
      [color=blue]
      > Jean Christophe Avard,[/color]
      [color=blue]
      >[/color]
      [color=blue]
      > Retrieve the client name and ID from the database and store the data in a[/color]
      [color=blue]
      > datatable.[/color]
      [color=blue]
      >[/color]
      [color=blue]
      > Assign the datatable to the combobox'x DataSource.[/color]
      [color=blue]
      >[/color]
      [color=blue]
      > Assign the client name to the combobox's DisplayMember.[/color]
      [color=blue]
      >[/color]
      [color=blue]
      > Assign the client ID to the combobox's ValueMember.[/color]
      [color=blue]
      >[/color]
      [color=blue]
      > In the combobox'x SelectedIndexCh anged event, retrieve the ID from the[/color]
      [color=blue]
      > combobox's SelectedValue property.[/color]
      [color=blue]
      >[/color]
      [color=blue]
      > Kerry Moorman[/color]
      [color=blue]
      >[/color]
      [color=blue]
      >[/color]
      [color=blue]
      >[/color]
      [color=blue]
      >[/color]
      [color=blue]
      > "Jean Christophe Avard" wrote:[/color]
      [color=blue]
      >[/color]
      [color=blue][color=green]
      > > Hi! I'm designing an application that produces invoices. I have a
      > > combobox[/color][/color]
      [color=blue][color=green]
      > > that is populated with the Name of every client in the database. What I[/color][/color]
      [color=blue][color=green]
      > > would like to do is to have the combobox to display the name, and to
      > > have[/color][/color]
      [color=blue][color=green]
      > > the value set to the ID of the record...[/color][/color]
      [color=blue][color=green]
      > >[/color][/color]
      [color=blue][color=green]
      > > Like in HTML where you have something like: <option
      > > value="ID_NUMBE R(primary[/color][/color]
      [color=blue][color=green]
      > > key)">CLIENT_NA ME</option>[/color][/color]
      [color=blue][color=green]
      > >[/color][/color]
      [color=blue][color=green]
      > > so, let's say the user selects "Client #2" in the combo box, then I
      > > would be[/color][/color]
      [color=blue][color=green]
      > > able to call the address of this client using the ID... SELECT * FROM[/color][/color]
      [color=blue][color=green]
      > > tbl_clients WHERE id_client = bombobox.select edValue ...[/color][/color]
      [color=blue][color=green]
      > >[/color][/color]
      [color=blue][color=green]
      > > I don't know if I'm making myself clear, I will be around, so ask
      > > anything[/color][/color]
      [color=blue][color=green]
      > > if I'm not enough clear. Thank y'all, this really apprecioated![/color][/color]
      [color=blue][color=green]
      > >[/color][/color]
      [color=blue][color=green]
      > > Jean Christophe Avard[/color][/color]


      Comment

      • Kerry Moorman

        #4
        Re: Advanced Help for Combo box Needed

        Jean Christophe Avard,

        It looks like the combobox's ValueMember property has not been correctly set.

        Be sure that the column name you supply to the ValueMember property is
        spelled exactly as in the datatable, including case.

        You might post your code where you retrieve the datatable and then use it as
        the combobox's data source, etc.

        Kerry Moorman


        "Jean Christophe Avard" wrote:
        [color=blue]
        > Thank you man, but I have another q7uestion... Why do I get an error with
        > this:
        >
        > sql = "SELECT * FROM tbl_clients WHERE id_client= " +
        > cboxClient.Sele ctedValue
        >
        > I also tried
        >
        > sql = "SELECT * FROM tbl_clients WHERE id_client= " +
        > cboxClient.Sele ctedValue.toStr ing()
        >
        > And it always give me an error
        >
        > "An unhandled exception of type 'System.Invalid CastException' occurred in
        > microsoft.visua lbasic.dll
        >
        > Additional information: Operator is not valid for string "SELECT * FROM
        > tbl_clients WHERE " and type 'DataRowView'."
        >
        > What is the way to go!?
        >
        > "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.com> wrote in message
        > news:<8DD4FCC2-ECF6-411E-9897-301350DD54D9@mi crosoft.com>...
        >[color=green]
        > > Jean Christophe Avard,[/color]
        >[color=green]
        > >[/color]
        >[color=green]
        > > Retrieve the client name and ID from the database and store the data in a[/color]
        >[color=green]
        > > datatable.[/color]
        >[color=green]
        > >[/color]
        >[color=green]
        > > Assign the datatable to the combobox'x DataSource.[/color]
        >[color=green]
        > >[/color]
        >[color=green]
        > > Assign the client name to the combobox's DisplayMember.[/color]
        >[color=green]
        > >[/color]
        >[color=green]
        > > Assign the client ID to the combobox's ValueMember.[/color]
        >[color=green]
        > >[/color]
        >[color=green]
        > > In the combobox'x SelectedIndexCh anged event, retrieve the ID from the[/color]
        >[color=green]
        > > combobox's SelectedValue property.[/color]
        >[color=green]
        > >[/color]
        >[color=green]
        > > Kerry Moorman[/color]
        >[color=green]
        > >[/color]
        >[color=green]
        > >[/color]
        >[color=green]
        > >[/color]
        >[color=green]
        > >[/color]
        >[color=green]
        > > "Jean Christophe Avard" wrote:[/color]
        >[color=green]
        > >[/color]
        >[color=green][color=darkred]
        > > > Hi! I'm designing an application that produces invoices. I have a
        > > > combobox[/color][/color]
        >[color=green][color=darkred]
        > > > that is populated with the Name of every client in the database. What I[/color][/color]
        >[color=green][color=darkred]
        > > > would like to do is to have the combobox to display the name, and to
        > > > have[/color][/color]
        >[color=green][color=darkred]
        > > > the value set to the ID of the record...[/color][/color]
        >[color=green][color=darkred]
        > > >[/color][/color]
        >[color=green][color=darkred]
        > > > Like in HTML where you have something like: <option
        > > > value="ID_NUMBE R(primary[/color][/color]
        >[color=green][color=darkred]
        > > > key)">CLIENT_NA ME</option>[/color][/color]
        >[color=green][color=darkred]
        > > >[/color][/color]
        >[color=green][color=darkred]
        > > > so, let's say the user selects "Client #2" in the combo box, then I
        > > > would be[/color][/color]
        >[color=green][color=darkred]
        > > > able to call the address of this client using the ID... SELECT * FROM[/color][/color]
        >[color=green][color=darkred]
        > > > tbl_clients WHERE id_client = bombobox.select edValue ...[/color][/color]
        >[color=green][color=darkred]
        > > >[/color][/color]
        >[color=green][color=darkred]
        > > > I don't know if I'm making myself clear, I will be around, so ask
        > > > anything[/color][/color]
        >[color=green][color=darkred]
        > > > if I'm not enough clear. Thank y'all, this really apprecioated![/color][/color]
        >[color=green][color=darkred]
        > > >[/color][/color]
        >[color=green][color=darkred]
        > > > Jean Christophe Avard[/color][/color]
        >
        >
        >[/color]

        Comment

        • Phil

          #5
          Re: Advanced Help for Combo box Needed

          Jean,

          Try using an ampersand & instead of the +.

          Rgds, Phil


          "Jean Christophe Avard" <NO_SP@M.BITC H> wrote in message
          news:%23HmWUkFn FHA.1372@TK2MSF TNGP10.phx.gbl. ..[color=blue]
          > Thank you man, but I have another q7uestion... Why do I get an error with
          > this:
          >
          > sql = "SELECT * FROM tbl_clients WHERE id_client= " +
          > cboxClient.Sele ctedValue
          >
          > I also tried
          >
          > sql = "SELECT * FROM tbl_clients WHERE id_client= " +
          > cboxClient.Sele ctedValue.toStr ing()
          >
          > And it always give me an error
          >
          > "An unhandled exception of type 'System.Invalid CastException' occurred in
          > microsoft.visua lbasic.dll
          >
          > Additional information: Operator is not valid for string "SELECT * FROM
          > tbl_clients WHERE " and type 'DataRowView'."
          >
          > What is the way to go!?
          >
          > "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.com> wrote in message
          > news:<8DD4FCC2-ECF6-411E-9897-301350DD54D9@mi crosoft.com>...
          >[color=green]
          >> Jean Christophe Avard,[/color]
          >[color=green]
          >>[/color]
          >[color=green]
          >> Retrieve the client name and ID from the database and store the data in a[/color]
          >[color=green]
          >> datatable.[/color]
          >[color=green]
          >>[/color]
          >[color=green]
          >> Assign the datatable to the combobox'x DataSource.[/color]
          >[color=green]
          >>[/color]
          >[color=green]
          >> Assign the client name to the combobox's DisplayMember.[/color]
          >[color=green]
          >>[/color]
          >[color=green]
          >> Assign the client ID to the combobox's ValueMember.[/color]
          >[color=green]
          >>[/color]
          >[color=green]
          >> In the combobox'x SelectedIndexCh anged event, retrieve the ID from the[/color]
          >[color=green]
          >> combobox's SelectedValue property.[/color]
          >[color=green]
          >>[/color]
          >[color=green]
          >> Kerry Moorman[/color]
          >[color=green]
          >>[/color]
          >[color=green]
          >>[/color]
          >[color=green]
          >>[/color]
          >[color=green]
          >>[/color]
          >[color=green]
          >> "Jean Christophe Avard" wrote:[/color]
          >[color=green]
          >>[/color]
          >[color=green][color=darkred]
          >> > Hi! I'm designing an application that produces invoices. I have a
          >> > combobox[/color][/color]
          >[color=green][color=darkred]
          >> > that is populated with the Name of every client in the database. What I[/color][/color]
          >[color=green][color=darkred]
          >> > would like to do is to have the combobox to display the name, and to
          >> > have[/color][/color]
          >[color=green][color=darkred]
          >> > the value set to the ID of the record...[/color][/color]
          >[color=green][color=darkred]
          >> >[/color][/color]
          >[color=green][color=darkred]
          >> > Like in HTML where you have something like: <option
          >> > value="ID_NUMBE R(primary[/color][/color]
          >[color=green][color=darkred]
          >> > key)">CLIENT_NA ME</option>[/color][/color]
          >[color=green][color=darkred]
          >> >[/color][/color]
          >[color=green][color=darkred]
          >> > so, let's say the user selects "Client #2" in the combo box, then I
          >> > would be[/color][/color]
          >[color=green][color=darkred]
          >> > able to call the address of this client using the ID... SELECT * FROM[/color][/color]
          >[color=green][color=darkred]
          >> > tbl_clients WHERE id_client = bombobox.select edValue ...[/color][/color]
          >[color=green][color=darkred]
          >> >[/color][/color]
          >[color=green][color=darkred]
          >> > I don't know if I'm making myself clear, I will be around, so ask
          >> > anything[/color][/color]
          >[color=green][color=darkred]
          >> > if I'm not enough clear. Thank y'all, this really apprecioated![/color][/color]
          >[color=green][color=darkred]
          >> >[/color][/color]
          >[color=green][color=darkred]
          >> > Jean Christophe Avard[/color][/color]
          >
          >[/color]


          Comment

          • Jean Christophe Avard

            #6
            Re: Advanced Help for Combo box Needed

            the cboxClient.Sele ctedValue.tostr ing returns System.DataRowV iew so I still
            have an error.... I also used & instead of + and its still the same...
            anyone!?


            this is the code in the load event of the form, where I populate the
            combobox

            Private Sub frmQuotation_Lo ad(ByVal sender As System.Object, ByVal e As
            System.EventArg s) Handles MyBase.Load


            ' create a connection

            Dim cn As SqlConnection = New SqlConnection

            ' open connection

            cn.ConnectionSt ring = strConn

            ' create sql query

            Dim sql As String

            If newQuotationTyp e = "client" Then

            sql = "SELECT id_client, first_name, last_name FROM tbl_clients ORDER BY
            last_name, first_name"

            ElseIf newQuotationTyp e = "supplier" Then

            sql = "SELECT id_supplier, name FROM tbl_suppliers ORDER BY name"

            End If

            ' create a data adapter

            Dim da As SqlDataAdapter = New SqlDataAdapter( sql, cn)

            ' create a dataset

            Dim ds As DataSet = New DataSet

            ' add table to the data set

            ds.Tables.Add(N ew DataTable("clie nts"))

            ' fill the data adapter

            da.Fill(ds.Tabl es("clients"))

            ' create a datarow

            Dim dr As DataRow

            ' populate combo box

            cboxClient.Data Source = ds.Tables("clie nts")

            If newQuotationTyp e = "client" Then

            cboxClient.Disp layMember = "last_name"

            cboxClient.Valu eMember = "id_client"

            Else

            cboxClient.Disp layMember = "name"

            cboxClient.Valu eMember = "id_supplie r"

            End If

            cn.Dispose()

            End Sub






            This is the code I use in the selectedValueCh anged event:

            Private Sub cboxClient_Sele ctedIndexChange d(ByVal sender As System.Object,
            ByVal e As System.EventArg s) Handles cboxClient.Sele ctedIndexChange d

            Dim conn As SqlConnection = New SqlConnection





            ' connection string

            conn.Connection String = strConn

            Dim sql As String

            If newQuotationTyp e = "client" Then

            sql = "SELECT * FROM tbl_clients WHERE id_client= " &
            cboxClient.Sele ctedValue

            ElseIf newQuotationTyp e = "supplier" Then

            sql = "SELECT * FROM tbl_suppliers WHERE id_supplier " &
            cboxClient.Sele ctedValue

            End If

            MessageBox.Show (sql)

            ' create a new data adapter

            Dim da As SqlDataAdapter = New SqlDataAdapter( sql, conn)

            ' create a new dataset

            Dim ds As DataSet = New DataSet

            ds.Tables.Add(N ew DataTable("addr ess"))

            da.Fill(ds.Tabl es("address"))

            Dim address As String = ds.Tables("addr ess").Rows(0)(" address").ToStr ing +
            vbNewLine

            Dim city As String = ds.Tables("addr ess").Rows(0)(" city").ToString + " (" +
            ds.Tables("addr ess").Rows(0)(" state").ToStrin g + ")" + vbNewLine

            Dim country As String = ds.Tables("addr ess").Rows(0)(" country").ToStr ing + "
            " + ds.Tables("addr ess").Rows(0)(" zipcode").ToStr ing + vbNewLine

            Dim phone As String = ds.Tables("addr ess").Rows(0)(" phone").ToStrin g +
            vbNewLine

            Dim fax As String = ds.Tables("addr ess").Rows(0)(" fax").ToString

            rtxtAddress.Tex t = address + city + country + phone + fax









            "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.com> wrote in message
            news:1E21681D-67A9-4381-AD4A-8143EB9383F0@mi crosoft.com...[color=blue]
            > Jean Christophe Avard,
            >
            > It looks like the combobox's ValueMember property has not been correctly
            > set.
            >
            > Be sure that the column name you supply to the ValueMember property is
            > spelled exactly as in the datatable, including case.
            >
            > You might post your code where you retrieve the datatable and then use it
            > as
            > the combobox's data source, etc.
            >
            > Kerry Moorman
            >
            >
            > "Jean Christophe Avard" wrote:
            >[color=green]
            >> Thank you man, but I have another q7uestion... Why do I get an error with
            >> this:
            >>
            >> sql = "SELECT * FROM tbl_clients WHERE id_client= " +
            >> cboxClient.Sele ctedValue
            >>
            >> I also tried
            >>
            >> sql = "SELECT * FROM tbl_clients WHERE id_client= " +
            >> cboxClient.Sele ctedValue.toStr ing()
            >>
            >> And it always give me an error
            >>
            >> "An unhandled exception of type 'System.Invalid CastException' occurred in
            >> microsoft.visua lbasic.dll
            >>
            >> Additional information: Operator is not valid for string "SELECT * FROM
            >> tbl_clients WHERE " and type 'DataRowView'."
            >>
            >> What is the way to go!?
            >>
            >> "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.com> wrote in message
            >> news:<8DD4FCC2-ECF6-411E-9897-301350DD54D9@mi crosoft.com>...
            >>[color=darkred]
            >> > Jean Christophe Avard,[/color]
            >>[color=darkred]
            >> >[/color]
            >>[color=darkred]
            >> > Retrieve the client name and ID from the database and store the data in
            >> > a[/color]
            >>[color=darkred]
            >> > datatable.[/color]
            >>[color=darkred]
            >> >[/color]
            >>[color=darkred]
            >> > Assign the datatable to the combobox'x DataSource.[/color]
            >>[color=darkred]
            >> >[/color]
            >>[color=darkred]
            >> > Assign the client name to the combobox's DisplayMember.[/color]
            >>[color=darkred]
            >> >[/color]
            >>[color=darkred]
            >> > Assign the client ID to the combobox's ValueMember.[/color]
            >>[color=darkred]
            >> >[/color]
            >>[color=darkred]
            >> > In the combobox'x SelectedIndexCh anged event, retrieve the ID from the[/color]
            >>[color=darkred]
            >> > combobox's SelectedValue property.[/color]
            >>[color=darkred]
            >> >[/color]
            >>[color=darkred]
            >> > Kerry Moorman[/color]
            >>[color=darkred]
            >> >[/color]
            >>[color=darkred]
            >> >[/color]
            >>[color=darkred]
            >> >[/color]
            >>[color=darkred]
            >> >[/color]
            >>[color=darkred]
            >> > "Jean Christophe Avard" wrote:[/color]
            >>[color=darkred]
            >> >[/color]
            >>[color=darkred]
            >> > > Hi! I'm designing an application that produces invoices. I have a
            >> > > combobox[/color]
            >>[color=darkred]
            >> > > that is populated with the Name of every client in the database. What
            >> > > I[/color]
            >>[color=darkred]
            >> > > would like to do is to have the combobox to display the name, and to
            >> > > have[/color]
            >>[color=darkred]
            >> > > the value set to the ID of the record...[/color]
            >>[color=darkred]
            >> > >[/color]
            >>[color=darkred]
            >> > > Like in HTML where you have something like: <option
            >> > > value="ID_NUMBE R(primary[/color]
            >>[color=darkred]
            >> > > key)">CLIENT_NA ME</option>[/color]
            >>[color=darkred]
            >> > >[/color]
            >>[color=darkred]
            >> > > so, let's say the user selects "Client #2" in the combo box, then I
            >> > > would be[/color]
            >>[color=darkred]
            >> > > able to call the address of this client using the ID... SELECT * FROM[/color]
            >>[color=darkred]
            >> > > tbl_clients WHERE id_client = bombobox.select edValue ...[/color]
            >>[color=darkred]
            >> > >[/color]
            >>[color=darkred]
            >> > > I don't know if I'm making myself clear, I will be around, so ask
            >> > > anything[/color]
            >>[color=darkred]
            >> > > if I'm not enough clear. Thank y'all, this really apprecioated![/color]
            >>[color=darkred]
            >> > >[/color]
            >>[color=darkred]
            >> > > Jean Christophe Avard[/color]
            >>
            >>
            >>[/color][/color]


            Comment

            • Kerry Moorman

              #7
              Re: Advanced Help for Combo box Needed

              Jean Christophe Avard,

              First assign a value to the combobox's Displaymember.

              Next, assign a value to the combobox's Valuemember.

              Then assign a value to the combobox's Datasource.

              The order of these steps seems to matter.

              Kerry Moorman


              "Jean Christophe Avard" wrote:
              [color=blue]
              > the cboxClient.Sele ctedValue.tostr ing returns System.DataRowV iew so I still
              > have an error.... I also used & instead of + and its still the same...
              > anyone!?
              >
              >
              > this is the code in the load event of the form, where I populate the
              > combobox
              >
              > Private Sub frmQuotation_Lo ad(ByVal sender As System.Object, ByVal e As
              > System.EventArg s) Handles MyBase.Load
              >
              >
              > ' create a connection
              >
              > Dim cn As SqlConnection = New SqlConnection
              >
              > ' open connection
              >
              > cn.ConnectionSt ring = strConn
              >
              > ' create sql query
              >
              > Dim sql As String
              >
              > If newQuotationTyp e = "client" Then
              >
              > sql = "SELECT id_client, first_name, last_name FROM tbl_clients ORDER BY
              > last_name, first_name"
              >
              > ElseIf newQuotationTyp e = "supplier" Then
              >
              > sql = "SELECT id_supplier, name FROM tbl_suppliers ORDER BY name"
              >
              > End If
              >
              > ' create a data adapter
              >
              > Dim da As SqlDataAdapter = New SqlDataAdapter( sql, cn)
              >
              > ' create a dataset
              >
              > Dim ds As DataSet = New DataSet
              >
              > ' add table to the data set
              >
              > ds.Tables.Add(N ew DataTable("clie nts"))
              >
              > ' fill the data adapter
              >
              > da.Fill(ds.Tabl es("clients"))
              >
              > ' create a datarow
              >
              > Dim dr As DataRow
              >
              > ' populate combo box
              >
              > cboxClient.Data Source = ds.Tables("clie nts")
              >
              > If newQuotationTyp e = "client" Then
              >
              > cboxClient.Disp layMember = "last_name"
              >
              > cboxClient.Valu eMember = "id_client"
              >
              > Else
              >
              > cboxClient.Disp layMember = "name"
              >
              > cboxClient.Valu eMember = "id_supplie r"
              >
              > End If
              >
              > cn.Dispose()
              >
              > End Sub
              >
              >
              >
              >
              >
              >
              > This is the code I use in the selectedValueCh anged event:
              >
              > Private Sub cboxClient_Sele ctedIndexChange d(ByVal sender As System.Object,
              > ByVal e As System.EventArg s) Handles cboxClient.Sele ctedIndexChange d
              >
              > Dim conn As SqlConnection = New SqlConnection
              >
              >
              >
              >
              >
              > ' connection string
              >
              > conn.Connection String = strConn
              >
              > Dim sql As String
              >
              > If newQuotationTyp e = "client" Then
              >
              > sql = "SELECT * FROM tbl_clients WHERE id_client= " &
              > cboxClient.Sele ctedValue
              >
              > ElseIf newQuotationTyp e = "supplier" Then
              >
              > sql = "SELECT * FROM tbl_suppliers WHERE id_supplier " &
              > cboxClient.Sele ctedValue
              >
              > End If
              >
              > MessageBox.Show (sql)
              >
              > ' create a new data adapter
              >
              > Dim da As SqlDataAdapter = New SqlDataAdapter( sql, conn)
              >
              > ' create a new dataset
              >
              > Dim ds As DataSet = New DataSet
              >
              > ds.Tables.Add(N ew DataTable("addr ess"))
              >
              > da.Fill(ds.Tabl es("address"))
              >
              > Dim address As String = ds.Tables("addr ess").Rows(0)(" address").ToStr ing +
              > vbNewLine
              >
              > Dim city As String = ds.Tables("addr ess").Rows(0)(" city").ToString + " (" +
              > ds.Tables("addr ess").Rows(0)(" state").ToStrin g + ")" + vbNewLine
              >
              > Dim country As String = ds.Tables("addr ess").Rows(0)(" country").ToStr ing + "
              > " + ds.Tables("addr ess").Rows(0)(" zipcode").ToStr ing + vbNewLine
              >
              > Dim phone As String = ds.Tables("addr ess").Rows(0)(" phone").ToStrin g +
              > vbNewLine
              >
              > Dim fax As String = ds.Tables("addr ess").Rows(0)(" fax").ToString
              >
              > rtxtAddress.Tex t = address + city + country + phone + fax
              >
              >
              >
              >
              >
              >
              >
              >
              >
              > "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.com> wrote in message
              > news:1E21681D-67A9-4381-AD4A-8143EB9383F0@mi crosoft.com...[color=green]
              > > Jean Christophe Avard,
              > >
              > > It looks like the combobox's ValueMember property has not been correctly
              > > set.
              > >
              > > Be sure that the column name you supply to the ValueMember property is
              > > spelled exactly as in the datatable, including case.
              > >
              > > You might post your code where you retrieve the datatable and then use it
              > > as
              > > the combobox's data source, etc.
              > >
              > > Kerry Moorman
              > >
              > >
              > > "Jean Christophe Avard" wrote:
              > >[color=darkred]
              > >> Thank you man, but I have another q7uestion... Why do I get an error with
              > >> this:
              > >>
              > >> sql = "SELECT * FROM tbl_clients WHERE id_client= " +
              > >> cboxClient.Sele ctedValue
              > >>
              > >> I also tried
              > >>
              > >> sql = "SELECT * FROM tbl_clients WHERE id_client= " +
              > >> cboxClient.Sele ctedValue.toStr ing()
              > >>
              > >> And it always give me an error
              > >>
              > >> "An unhandled exception of type 'System.Invalid CastException' occurred in
              > >> microsoft.visua lbasic.dll
              > >>
              > >> Additional information: Operator is not valid for string "SELECT * FROM
              > >> tbl_clients WHERE " and type 'DataRowView'."
              > >>
              > >> What is the way to go!?
              > >>
              > >> "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.com> wrote in message
              > >> news:<8DD4FCC2-ECF6-411E-9897-301350DD54D9@mi crosoft.com>...
              > >>
              > >> > Jean Christophe Avard,
              > >>
              > >> >
              > >>
              > >> > Retrieve the client name and ID from the database and store the data in
              > >> > a
              > >>
              > >> > datatable.
              > >>
              > >> >
              > >>
              > >> > Assign the datatable to the combobox'x DataSource.
              > >>
              > >> >
              > >>
              > >> > Assign the client name to the combobox's DisplayMember.
              > >>
              > >> >
              > >>
              > >> > Assign the client ID to the combobox's ValueMember.
              > >>
              > >> >
              > >>
              > >> > In the combobox'x SelectedIndexCh anged event, retrieve the ID from the
              > >>
              > >> > combobox's SelectedValue property.
              > >>
              > >> >
              > >>
              > >> > Kerry Moorman
              > >>
              > >> >
              > >>
              > >> >
              > >>
              > >> >
              > >>
              > >> >
              > >>
              > >> > "Jean Christophe Avard" wrote:
              > >>
              > >> >
              > >>
              > >> > > Hi! I'm designing an application that produces invoices. I have a
              > >> > > combobox
              > >>
              > >> > > that is populated with the Name of every client in the database. What
              > >> > > I
              > >>
              > >> > > would like to do is to have the combobox to display the name, and to
              > >> > > have
              > >>
              > >> > > the value set to the ID of the record...
              > >>
              > >> > >
              > >>
              > >> > > Like in HTML where you have something like: <option
              > >> > > value="ID_NUMBE R(primary
              > >>
              > >> > > key)">CLIENT_NA ME</option>
              > >>
              > >> > >
              > >>
              > >> > > so, let's say the user selects "Client #2" in the combo box, then I
              > >> > > would be
              > >>
              > >> > > able to call the address of this client using the ID... SELECT * FROM
              > >>
              > >> > > tbl_clients WHERE id_client = bombobox.select edValue ...
              > >>
              > >> > >
              > >>
              > >> > > I don't know if I'm making myself clear, I will be around, so ask
              > >> > > anything
              > >>
              > >> > > if I'm not enough clear. Thank y'all, this really apprecioated!
              > >>
              > >> > >
              > >>
              > >> > > Jean Christophe Avard
              > >>
              > >>
              > >>[/color][/color]
              >
              >
              >[/color]

              Comment

              Working...