none
using sqldatasource to populate a variable RRS feed

  • Question

  • I am sure there is an easy way to do this!

     

    I have a aspx form (running with c#) and have created an sqldatasource. They way the sql has been written means only one entry will be returned (one cell / one column). I basically want to access this from the aspx.cs file so that I can use it in an if statement.

     

    I am having trouble understanding how I can get to the data from the aspx.cs form.

     

    Does anyone have any examples or offer any help?

     

    Not sure if you would access this different if there was more than one entry!!

     

    any help would be appreciated.

    Monday, August 6, 2007 4:25 PM

Answers

  • You can do something like this:

     

    DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);

    foreach (DataRow dr in dv.Table.Rows)

    {

    Response.Write(dr[2].ToString() + " ");

    }

     

    This will create a DataView out of your sqldatasource. Using the DataView you can access individual rows and do whatever you want to with them.

     

    Hope this helps.

     

    QIJ.

    Monday, August 6, 2007 5:51 PM