better solution?

  • Thread starter Thread starter Chris Taylor
  • Start date Start date
C

Chris Taylor

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 said:
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
 
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
 
Back
Top