better solution?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zarish

    #1

    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(descri ption) from cars";
    SqlDataAdapter da = new SqlDataAdapter (sqlQuery,conn) ;
    DataSet ds = new DataSet();
    da.Fill (ds,"Cars");
    return ds;
    }



    private void Form1_Load(obje ct sender, System.EventArg s e)
    {
    string delimStr = ",";
    char [] delimiter = delimStr.ToChar Array();
    string [] split = null;
    ser=new Service1();
    ds=ser.getAllCa rTypes();
    String data=PrintRows( ds,"description ");
    cmbType.Items.C lear();
    split = data.Split(deli miter);
    foreach (string s in split)
    {
    if (s!="")
    cmbType.Items.A dd(s);
    }
    cmbType.Selecte dIndex=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




  • Chris Taylor

    #2
    Re: better solution?

    Hi,

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

    ds=ser.getAllCa rTypes();
    foreach( DataRow dr in ds.Tables[0].Rows )
    {
    if ( !dr.IsNull(0) ) // Check that the column is not null
    cmbType.Items.A dd( 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["descriptio n"].

    Hope this helps

    Chris Taylor

    "zarish" <shahrukh@hotma il.com> wrote in message
    news:ecqv4trcDH A.1044@TK2MSFTN GP10.phx.gbl...[color=blue]
    > 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(descri ption) from cars";
    > SqlDataAdapter da = new SqlDataAdapter (sqlQuery,conn) ;
    > DataSet ds = new DataSet();
    > da.Fill (ds,"Cars");
    > return ds;
    > }
    >
    >
    >
    > private void Form1_Load(obje ct sender, System.EventArg s e)
    > {
    > string delimStr = ",";
    > char [] delimiter = delimStr.ToChar Array();
    > string [] split = null;
    > ser=new Service1();
    > ds=ser.getAllCa rTypes();
    > String data=PrintRows( ds,"description ");
    > cmbType.Items.C lear();
    > split = data.Split(deli miter);
    > foreach (string s in split)
    > {
    > if (s!="")
    > cmbType.Items.A dd(s);
    > }
    > cmbType.Selecte dIndex=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
    >
    >
    >
    >[/color]


    Comment

    • Carl Prothman [MVP]

      #3
      Re: better solution?

      "zarish" <shahrukh@hotma il.com> wrote[color=blue]
      > im using a disconnected recordset feature of ado.net in my webservice and
      > pasing it to my application.
      >
      > ds=ser.getAllCa rTypes();
      > String data=PrintRows( ds,"description ");
      > cmbType.Items.C lear();
      > split = data.Split(deli miter);[/color]

      Try the following:

      cmbType.Items.C lear();
      cmbType.DataSou rce = ds.Tables(0);
      cmbType.Display Member = "descriptio n";
      cmbType.ValueMe mber = "descriptio n";

      --

      Thanks,
      Carl Prothman
      Microsoft ASP.NET MVP





      Comment

      Working...