Very odd behavior with DataTable.Select 
Author Message
 Very odd behavior with DataTable.Select

Hello,

I have a class that exposes a DataTable as a property. The class is
derived from the ComboBox and the DataTable is what has been bound to
the ComboBox control. I have one field of my DataTable set to the
DisplayMember and another set to the ValueMember. I have a third field
that I would like to access. I tried the following:

------------------
        Dim mySelectString As String
        Dim myRows As DataRow()

        mySelectString = "TypeCodeID = " & ReferredByList.SelectedValue
        myRows = ReferredByList.DataTable.Select(mySelectString)
------------------

With this code I got an error that the DataRowView could not be
converted to an integer. Next I tried:

------------------
mySelectString = "TypeCodeID = " & ReferredByList.SelectedValue
("TypeCodeID")
------------------

I received another error. While in debug mode I went to the immediate
window and typed:
?ReferredByList.SelectedValue

The immediate window showed a value of 32 (an integer...). Hmmmm, odd
that it gave me an error. I changed the code back and got the error
again. I went to the immediate window and typed:
?ReferredByList.SelectedValue("TypeCodeID")

I got back a value of 32 (still an integer...). So, basically, whichever
way I try to code it, it works the *other* way. If I switch my syntax it
no longer works that way and the other way now seems to work.

Any ideas on:

1. How to do something like this (i.e., get at a DataTable column for a
ComboBox).
2. Why this odd behavior is occurring.

        Thanks,
          -Tom.



Mon, 03 Jan 2005 05:23:03 GMT  
 Very odd behavior with DataTable.Select
No idea as to why it is doing that, but try:

mySelectString = "TypeCodeID = " & ReferredByList.SelectedValue.ToString

HTH

David



Quote:
> Hello,

> I have a class that exposes a DataTable as a property. The class is
> derived from the ComboBox and the DataTable is what has been bound to
> the ComboBox control. I have one field of my DataTable set to the
> DisplayMember and another set to the ValueMember. I have a third field
> that I would like to access. I tried the following:

> ------------------
>         Dim mySelectString As String
>         Dim myRows As DataRow()

>         mySelectString = "TypeCodeID = " & ReferredByList.SelectedValue
>         myRows = ReferredByList.DataTable.Select(mySelectString)
> ------------------

> With this code I got an error that the DataRowView could not be
> converted to an integer. Next I tried:

> ------------------
> mySelectString = "TypeCodeID = " & ReferredByList.SelectedValue
> ("TypeCodeID")
> ------------------

> I received another error. While in debug mode I went to the immediate
> window and typed:
> ?ReferredByList.SelectedValue

> The immediate window showed a value of 32 (an integer...). Hmmmm, odd
> that it gave me an error. I changed the code back and got the error
> again. I went to the immediate window and typed:
> ?ReferredByList.SelectedValue("TypeCodeID")

> I got back a value of 32 (still an integer...). So, basically, whichever
> way I try to code it, it works the *other* way. If I switch my syntax it
> no longer works that way and the other way now seems to work.

> Any ideas on:

> 1. How to do something like this (i.e., get at a DataTable column for a
> ComboBox).
> 2. Why this odd behavior is occurring.

> Thanks,
>   -Tom.



Mon, 03 Jan 2005 07:10:02 GMT  
 Very odd behavior with DataTable.Select
I had actually tried that before and I end up getting a string that is:

"TypeCodeID = System.Data.DataRowView"

        Thanks,
          -Tom.


Quote:
> No idea as to why it is doing that, but try:

> mySelectString = "TypeCodeID = " & ReferredByList.SelectedValue.ToString

> HTH

> David



> > Hello,

> > I have a class that exposes a DataTable as a property. The class is
> > derived from the ComboBox and the DataTable is what has been bound to
> > the ComboBox control. I have one field of my DataTable set to the
> > DisplayMember and another set to the ValueMember. I have a third field
> > that I would like to access. I tried the following:

> > ------------------
> >         Dim mySelectString As String
> >         Dim myRows As DataRow()

> >         mySelectString = "TypeCodeID = " & ReferredByList.SelectedValue
> >         myRows = ReferredByList.DataTable.Select(mySelectString)
> > ------------------

> > With this code I got an error that the DataRowView could not be
> > converted to an integer. Next I tried:

> > ------------------
> > mySelectString = "TypeCodeID = " & ReferredByList.SelectedValue
> > ("TypeCodeID")
> > ------------------

> > I received another error. While in debug mode I went to the immediate
> > window and typed:
> > ?ReferredByList.SelectedValue

> > The immediate window showed a value of 32 (an integer...). Hmmmm, odd
> > that it gave me an error. I changed the code back and got the error
> > again. I went to the immediate window and typed:
> > ?ReferredByList.SelectedValue("TypeCodeID")

> > I got back a value of 32 (still an integer...). So, basically, whichever
> > way I try to code it, it works the *other* way. If I switch my syntax it
> > no longer works that way and the other way now seems to work.

> > Any ideas on:

> > 1. How to do something like this (i.e., get at a DataTable column for a



Mon, 03 Jan 2005 08:29:18 GMT  
 Very odd behavior with DataTable.Select
I think the select needs to look something like this

myTable.select("myColumn = '1234'")

notice the single quotes, therefore

 mySelectString = "TypeCodeID = '" & ReferredByList.SelectedValue & '"

should work.

Btw,  It sound like you're doing a select on the same table you've bound to
the combo.  If so, you can get the selected row directly with...

dim r as datarow = ctype(myCombo.SelectedItem, DataRowView).row



Quote:
> Hello,

> I have a class that exposes a DataTable as a property. The class is
> derived from the ComboBox and the DataTable is what has been bound to
> the ComboBox control. I have one field of my DataTable set to the
> DisplayMember and another set to the ValueMember. I have a third field
> that I would like to access. I tried the following:

> ------------------
>         Dim mySelectString As String
>         Dim myRows As DataRow()

>         mySelectString = "TypeCodeID = " & ReferredByList.SelectedValue
>         myRows = ReferredByList.DataTable.Select(mySelectString)
> ------------------

> With this code I got an error that the DataRowView could not be
> converted to an integer. Next I tried:

> ------------------
> mySelectString = "TypeCodeID = " & ReferredByList.SelectedValue
> ("TypeCodeID")
> ------------------

> I received another error. While in debug mode I went to the immediate
> window and typed:
> ?ReferredByList.SelectedValue

> The immediate window showed a value of 32 (an integer...). Hmmmm, odd
> that it gave me an error. I changed the code back and got the error
> again. I went to the immediate window and typed:
> ?ReferredByList.SelectedValue("TypeCodeID")

> I got back a value of 32 (still an integer...). So, basically, whichever
> way I try to code it, it works the *other* way. If I switch my syntax it
> no longer works that way and the other way now seems to work.

> Any ideas on:

> 1. How to do something like this (i.e., get at a DataTable column for a
> ComboBox).
> 2. Why this odd behavior is occurring.

> Thanks,
>   -Tom.



Mon, 03 Jan 2005 20:39:28 GMT  
 Very odd behavior with DataTable.Select
Sorry, you may need the select to be

mySelectString = "TypeCodeID = '" & ReferredByList.SelectedValue.ToString &
'"

if selected value is not a string


Quote:
> I think the select needs to look something like this

> myTable.select("myColumn = '1234'")

> notice the single quotes, therefore

>  mySelectString = "TypeCodeID = '" & ReferredByList.SelectedValue & '"

> should work.

> Btw,  It sound like you're doing a select on the same table you've bound
to
> the combo.  If so, you can get the selected row directly with...

> dim r as datarow = ctype(myCombo.SelectedItem, DataRowView).row



> > Hello,

> > I have a class that exposes a DataTable as a property. The class is
> > derived from the ComboBox and the DataTable is what has been bound to
> > the ComboBox control. I have one field of my DataTable set to the
> > DisplayMember and another set to the ValueMember. I have a third field
> > that I would like to access. I tried the following:

> > ------------------
> >         Dim mySelectString As String
> >         Dim myRows As DataRow()

> >         mySelectString = "TypeCodeID = " & ReferredByList.SelectedValue
> >         myRows = ReferredByList.DataTable.Select(mySelectString)
> > ------------------

> > With this code I got an error that the DataRowView could not be
> > converted to an integer. Next I tried:

> > ------------------
> > mySelectString = "TypeCodeID = " & ReferredByList.SelectedValue
> > ("TypeCodeID")
> > ------------------

> > I received another error. While in debug mode I went to the immediate
> > window and typed:
> > ?ReferredByList.SelectedValue

> > The immediate window showed a value of 32 (an integer...). Hmmmm, odd
> > that it gave me an error. I changed the code back and got the error
> > again. I went to the immediate window and typed:
> > ?ReferredByList.SelectedValue("TypeCodeID")

> > I got back a value of 32 (still an integer...). So, basically, whichever
> > way I try to code it, it works the *other* way. If I switch my syntax it
> > no longer works that way and the other way now seems to work.

> > Any ideas on:

> > 1. How to do something like this (i.e., get at a DataTable column for a
> > ComboBox).
> > 2. Why this odd behavior is occurring.

> > Thanks,
> >   -Tom.



Mon, 03 Jan 2005 20:43:19 GMT  
 Very odd behavior with DataTable.Select

says...

Quote:
> I think the select needs to look something like this

> myTable.select("myColumn = '1234'")

> notice the single quotes, therefore

>  mySelectString = "TypeCodeID = '" & ReferredByList.SelectedValue & '"

> should work.

> Btw,  It sound like you're doing a select on the same table you've bound to
> the combo.  If so, you can get the selected row directly with...

> dim r as datarow = ctype(myCombo.SelectedItem, DataRowView).row

That was exactly what I needed and works perfectly. Thanks!

I'm still a little stumped as to the results that I was seeing with the
other method. For example, your code above would have given me the same
error that I was getting, because it was saying that .SelectedValue is a
DataRowView and cannot be converted to a string. Unless of course I
tried to access one of the DataRowView properties and then it would tell
me that it was an integer.

Anyway, it works now and I like the other method much better - seems a
lot cleaner, so thanks!

        Thanks,
           -Tom.



Mon, 03 Jan 2005 20:57:27 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Odd behavior by socket.select()

2. Odd behavior with Dates -A2K

3. Access 2.0 odd transaction behavior

4. Odd Behavior With CommitTrans

5. odd Add Note behavior

6. Externally adding tasks via SQL gives odd behavior

7. Odd recalc behavior with shapeobj.duplicate

8. Odd behavior when inserting TextBox1 into header

9. odd behavior in Qbasic

10. Help, VFP - List boxes on pageframes with odd behavior

11. Odd printing behavior on Win2000

12. Odd behavior with setfocus

 

 
Powered by phpBB® Forum Software