Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo

  More data woes.... (Thursday, December 23, 2004)




Found the following interesting discussion in the Newsgroups:

More data woes....
by:Graham Blandford

Hi all,

Well I abandoned the use of a datagrid in my windows form and have opted to
use a listbox instead.

I have, following a helpful article created an item class and loaded it with
values from an ADO recordset.

Now, if I read the data I get a field (clientid) looking like this;

{FE84ACD5-8263-11D7-B0E7-0080AE000001}

when in fact, the actual data (as viewed using say a binding to a datagrid)
looks like this;

fe84acd5-8263-11d7-b0e7-0080ae000001

Why is it placing {} around the string and CASING up?
AAARRRRGGGHHHH!!

Here's some code snippets - where could this be happening?

By the way - I'm forced to use ADO as the dataaccess method in this case -
it is pulled from a 3rd-party reference which returns an ADO recordset.
I guess I could load the data into a dataset prior to reading - but then I'm
not sure how I read through the set sequentially.....


The defined class:-

Private clientid As String
Private Class ClientListItem
Private clientid As String
Private clientname As String
Public Sub New(ByVal id As String, ByVal name As String)
clientid = id
clientname = name
End Sub
Public Property listclientid() As String
Get
Return clientid
End Get
Set(ByVal Value As String)
clientid = Value
End Set
End Property
Public Property listclientname() As String
Get
Return clientname
End Get
Set(ByVal Value As String)
clientname = Value
End Set
End Property
Public Overrides Function ToString() As String
' this can be whatever you want to show in the listbox
Return clientname & " " & clientid
End Function
End Class
And here's the loading of the data into the listbox;
If rsclients.State <> ADODB.ObjectStateEnum.adStateClosed Then
rsclients.MoveFirst()
While Not rsclients.EOF
id = Trim(rsclients.Fields(0).Value)
name = rsclients.Fields("clientname").Value
' Debug.WriteLine(rsclients.Fields("clientid").Value & " " &
rsclients.Fields("clientname").Value)
' Debug.WriteLine(id.ToString & " " & name.ToString)
Dim liclients As New ClientListItem(id.ToString, name.ToString)
lstClients.Items.Add(liclients)
rsclients.MoveNext()
End While
End If
If anyone has any ideas I'd appreciate it.

Thanks,
Graham


 Reply:
by:Graham Blandford

 Ok.. Ok... yep.. I got it... GUID.....

Thanks, for anyone that already took the time to reply......

Graham


 Reply:
by:CJ Taylor

 Datagrid columns will call the ToString() method of the datatype (which all
have in .NET since they all derive from object). Thats how you get your
display

In your case, your using a GUID which when calling the ToString() removes
the {}'s








 
Previous Posts
    - Serial Communication
    - VB and 'graphical' languages
    - Custom Control Postback Problems
    - [Help] my form lost my Tab page1 & page 2.
    - [HELP] All textbox and button disappear in design ...
    - Problems with ListAvailableSQLServers (SQLDMO)
    - debuging web controls
    - Microsoft.Office.Interop.Excel
    - Double-click event in datagrid?
    - Catching "Came from Row" on a RowChange in Datagri...

Archives
    - 10/03/2004 - 10/10/2004
    - 10/10/2004 - 10/17/2004
    - 10/17/2004 - 10/24/2004
    - 10/24/2004 - 10/31/2004
    - 10/31/2004 - 11/07/2004
    - 11/21/2004 - 11/28/2004
    - 11/28/2004 - 12/05/2004
    - 12/05/2004 - 12/12/2004
    - 12/12/2004 - 12/19/2004
    - 12/19/2004 - 12/26/2004
    - 12/26/2004 - 01/02/2005
    - 01/23/2005 - 01/30/2005
    - 01/01/2006 - 01/08/2006
    - 09/24/2006 - 10/01/2006


Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland