473,385 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Using DataTable.Select in ComboBox

I'm looking at using the result of DataTable.Select as the DataSource
for a ComboBox. Is there an easy way to do this with a minimum of
code. I tried to bludgeon it into submission by writing:
myComboBox.DataSource = myDataTable.Select
and got appropriately vulgar results.

I know I could loop through the array of DataRows and add them to
another DataTable and then use that as the DataSource for a ComboBox.
If I have to do that much coding I'd probably look into using a
DataView instead.

Thanks for any assistance.
Gene H
Nov 20 '05 #1
4 8208
Hi Gene,

The easiest way I can think of - there may well be better - is to assign a
datarow array the .select rows; then loop through the array and add the row
column you need.

I tried your approach, and, yes, your definition of 'vulgar' was
appropriate!

HTH,

Bernie

"Gene Hubert" <gw******@hotmail.com> wrote in message
news:7e**************************@posting.google.c om...
I'm looking at using the result of DataTable.Select as the DataSource
for a ComboBox. Is there an easy way to do this with a minimum of
code. I tried to bludgeon it into submission by writing:
myComboBox.DataSource = myDataTable.Select
and got appropriately vulgar results.

I know I could loop through the array of DataRows and add them to
another DataTable and then use that as the DataSource for a ComboBox.
If I have to do that much coding I'd probably look into using a
DataView instead.

Thanks for any assistance.
Gene H

Nov 20 '05 #2
Gene,
If you are setting DataSource, I would recommend using a DataView instead.
myComboBox.DataSource = New DataView(myDataTable, ...)
David Sceppa's book "Microsoft ADO.NET - Core Reference" from MS Press
covers using a DataView verses using the DataTable.Select methods and when
you would or would not use each.

David's book is both a good tutorial on ADO.NET plus a good desk reference
once you know ADO.NET!

Hope this helps
Jay

"Gene Hubert" <gw******@hotmail.com> wrote in message
news:7e**************************@posting.google.c om... I'm looking at using the result of DataTable.Select as the DataSource
for a ComboBox. Is there an easy way to do this with a minimum of
code. I tried to bludgeon it into submission by writing:
myComboBox.DataSource = myDataTable.Select
and got appropriately vulgar results.

I know I could loop through the array of DataRows and add them to
another DataTable and then use that as the DataSource for a ComboBox.
If I have to do that much coding I'd probably look into using a
DataView instead.

Thanks for any assistance.
Gene H

Nov 20 '05 #3
Cor
Hi Gene,

In addition to Jay B.

I also suggest to use the dataview.
\\\
dim dv as new dataview(mydataset.tables("mytable")
dv.rowfilter = "mysortitem < 100"
dv.sort = "mysortitem"
mycombobox.datasource = dv
mycombobox.displaymember = "xx"
///
This give you with a miniumum of code the maximum results in my idea.

Cor
I'm looking at using the result of DataTable.Select as the DataSource
for a ComboBox. Is there an easy way to do this with a minimum of
code. I tried to bludgeon it into submission by writing:
myComboBox.DataSource = myDataTable.Select
and got appropriately vulgar results.

I know I could loop through the array of DataRows and add them to
another DataTable and then use that as the DataSource for a ComboBox.
If I have to do that much coding I'd probably look into using a
DataView instead.

Nov 20 '05 #4
Thanks much to everyone. I'm definitely looking for miniumum code and
maximum results. It seems that an array of datarows requires more
coding that I prefer to make it useful to a ComboBox. I'll be going
with a dataview.

Gene H.

"Cor" <no*@non.com> wrote in message news:<#Q*************@TK2MSFTNGP11.phx.gbl>...
Hi Gene,

In addition to Jay B.

I also suggest to use the dataview.
\\\
dim dv as new dataview(mydataset.tables("mytable")
dv.rowfilter = "mysortitem < 100"
dv.sort = "mysortitem"
mycombobox.datasource = dv
mycombobox.displaymember = "xx"
///
This give you with a miniumum of code the maximum results in my idea.

Cor

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Luc | last post by:
I am using Visual Studio 2003 and am getting lousy performance after using a datatable select and then trying to assign a value to a column of the row that was found: DataTable dt = new...
3
by: Dan V. | last post by:
How can I use real SQL on a DataTable? i.e. not array of rows using a filter... as in DataTable.Select. I read at : microsoft.public.dotnet.framework.adonet "As others have posted: There is no...
4
by: Kris Rudin | last post by:
I am displaying a table of information on a web page, using an asp:table that I populate dynamically. On this page I give the user the options to group the rows by certain fields, and/or filter the...
1
by: Solel Software | last post by:
Hi, I have a DataTable that I am attempting to sort using Datatable.Select and for some reason the sort is not working correctly. It is putting the row that should be first at the end (as the...
1
by: Diffident | last post by:
Hello All, I am trying to filter rows in a datatable based on filtercriteria and sortcriteria using the datatable.select() method. I am encountering a strange behavior in this process. Here is...
0
by: eye5600 | last post by:
I'm using DataTable.Select to find rows for specific persons. All goes well until I come to the last name of O'Hearn. How do I speciify the filter expression when the name contains an apostrophe?
4
by: Aryan | last post by:
Hi, I am having problem with DataTable.Select() method. I am using ASP.NET 2.0. I have DataSet which reads data from XML file using DataSet.ReadXML(). Now this dataset has various datatable,...
1
by: Maxwell2006 | last post by:
Hi, I am working with strongly typed datatables. What is the most efficient way to build a new DataTAble based on the result of DataTable.Select? At this point I use a foreach loop to do the...
4
by: Massimo | last post by:
Hi to All, i'm using C# in .NET 2.0 and i have a DataTable A with a column of type TimeSpan used to store HOUR info. I'm trying to filter my DataTable A selecting only rows that have the column...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.