By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,530 Members | 891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,530 IT Pros & Developers. It's quick & easy.

better solution?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.