473,378 Members | 1,280 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,378 software developers and data experts.

better solution?

hi,
im using a disconnected recordset feature of ado.net in my webservice and
pasing it to my application.

[WebMethod]
public DataSet getAllCarTypes()
{
string sqlQuery = "select distinct(description) from cars";
SqlDataAdapter da = new SqlDataAdapter (sqlQuery,conn);
DataSet ds = new DataSet();
da.Fill (ds,"Cars");
return ds;
}

private void Form1_Load(object sender, System.EventArgs e)
{
string delimStr = ",";
char [] delimiter = delimStr.ToCharArray();
string [] split = null;
ser=new Service1();
ds=ser.getAllCarTypes();
String data=PrintRows(ds,"description");
cmbType.Items.Clear();
split = data.Split(delimiter);
foreach (string s in split)
{
if (s!="")
cmbType.Items.Add(s);
}
cmbType.SelectedIndex=0;
}

here i am trying to get the description column only from the dataset.
i feel this approach is a very long one.. can anyone suggest a shorter
approach?

thanx

Zarish


Jul 19 '05 #1
2 1375
Hi,

You can enumerate the rows in the DataTable that is returned in the DataSet

ds=ser.getAllCarTypes();
foreach( DataRow dr in ds.Tables[0].Rows )
{
if ( !dr.IsNull(0) ) // Check that the column is not null
cmbType.Items.Add( dr[0] );
}

The above example uses 0 for the table and 0 for the column, this is based
on the sample you provided. In both cases you could also use the string name
for each as in ds.Tables["Table1"].Rows and dr["description"].

Hope this helps

Chris Taylor

"zarish" <sh******@hotmail.com> wrote in message
news:ec**************@TK2MSFTNGP10.phx.gbl...
hi,
im using a disconnected recordset feature of ado.net in my webservice and
pasing it to my application.

[WebMethod]
public DataSet getAllCarTypes()
{
string sqlQuery = "select distinct(description) from cars";
SqlDataAdapter da = new SqlDataAdapter (sqlQuery,conn);
DataSet ds = new DataSet();
da.Fill (ds,"Cars");
return ds;
}

private void Form1_Load(object sender, System.EventArgs e)
{
string delimStr = ",";
char [] delimiter = delimStr.ToCharArray();
string [] split = null;
ser=new Service1();
ds=ser.getAllCarTypes();
String data=PrintRows(ds,"description");
cmbType.Items.Clear();
split = data.Split(delimiter);
foreach (string s in split)
{
if (s!="")
cmbType.Items.Add(s);
}
cmbType.SelectedIndex=0;
}

here i am trying to get the description column only from the dataset.
i feel this approach is a very long one.. can anyone suggest a shorter
approach?

thanx

Zarish

Jul 19 '05 #2
"zarish" <sh******@hotmail.com> wrote
im using a disconnected recordset feature of ado.net in my webservice and
pasing it to my application.

ds=ser.getAllCarTypes();
String data=PrintRows(ds,"description");
cmbType.Items.Clear();
split = data.Split(delimiter);


Try the following:

cmbType.Items.Clear();
cmbType.DataSource = ds.Tables(0);
cmbType.DisplayMember = "description";
cmbType.ValueMember = "description";

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com


Jul 19 '05 #3

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

Similar topics

7
by: david | last post by:
I write a program which returns the maximum of three input integers. both can run weil in the DEV-C++ , but I just wonder which one is better, and I also want to make it clear that if I use the...
16
by: Bhushit Joshipura | last post by:
This post contains one question and one proposal. A. May I know why order of evaluation of arguments is not specified in C/C++? I asked a question in comp.lang.c++ for the following...
43
by: Rob R. Ainscough | last post by:
I realize I'm learning web development and there is a STEEP learning curve, but so far I've had to learn: HTML XML JavaScript ASP.NET using VB.NET ..NET Framework ADO.NET SSL
11
by: Daylor | last post by:
hi. im using option strict on. im doing in ,from the simple reason ,to be warn when there are implict conversion like string to int ,int to string. BUT. the price ,(now i see ), is very bad....
9
by: seberino | last post by:
I have been using distuils for a while and was wondering when Python Eggs (new project) is better? So basically Python Eggs precompiles and compresses binaries for you so you just have to load...
8
by: hugh webster | last post by:
MySql seems to only accept dates as 'yyyy-mm-dd'. How do I do that when the user might input dd/mm/yy, or d.m.yyyy (I'm in Europe)? I know I can do sscanf, or explode to rebuild the date string -...
39
by: windandwaves | last post by:
Hi Folk I have to store up to eight boolean bits of information about an item in my database. e.g. with restaurant drive-through facility yellow windows
2
by: kaferro | last post by:
I use the following code to reset an ID when an order has been filled by more than one trade. For example, order= buy 9 corn, order ID = 101. If the order is filled with three separate trades of,...
13
by: S James S Stapleton | last post by:
I have some code, and I want to make it future-resistant. I have a bunch of variables that are set up run-time, and once set up, should act as constants. I don't want to #define them, because their...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.