Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ComboBox Load
Message
From
21/10/2003 12:40:33
 
General information
Forum:
ASP.NET
Category:
Forms
Title:
Miscellaneous
Thread ID:
00839795
Message ID:
00840719
Views:
20
This message has been marked as a message which has helped to the initial question of the thread.
Jason,

>>If I dispose of the datatable in this sub then the combobox will not be loaded. Any suggestions?<

Don't bother disposing the datatable ... it's local to the method anyway and will be gone when the method is done executing.

Another way you can do this is to sub-class your ComboBox and use the sub-class on your forms. This code would still be in your sub-class ... well, more or less anyway ... it's not a good idea to actually put the DataAccess stuff in a UI component.

~~Bonnie


>Have a look
>
>
>Public Sub LoadUserCombo(ByRef cbo As ComboBox)
>            'Load the combobox
>            Dim sSQL As String
>            Dim dt As New DataTable()
>
>            'Get the users
>            sSQL = " SELECT nlUserID, tUserName "
>            sSQL += " FROM Users "
>            sSQL += " WHERE (lDeleted = " & oSQLUser.SQLBoolean(False) & ") "
>            sSQL += " ORDER BY tUserName "
>
>            Try
>
>                'Open the connection
>                oSQLUser.ConnectionString = Constants.SIMON_SQL_Connect
>                oSQLUser.OpenDBConnection()
>
>                'Get the datatable
>                dt = oSQLUser.GetDataTable(sSQL)
>
>                'Close the connection
>                oSQLUser.CloseDBConnection()
>
>                'Bind it to the combobox
>                cbo.DataSource = dt
>                cbo.DisplayMember = "tUserName"
>                cbo.ValueMember = "nlUserID"
>                cbo.SelectedIndex = 0
>
>            Catch exp As Exception
>                RaiseEvent ErrorRaised(exp.Source, exp.Message)
>            End Try
>
>        End Sub
>
>If I dispose of the datatable in this sub then the combobox will not be loaded. Any suggestions?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform