Accessing data without the controls

Last post 08-19-2006 10:23 PM by wsmonroe. 10 replies.

Sort Posts:

  • Accessing data without the controls

    05-28-2006, 6:21 AM
    • Member
      45 point Member
    • dirkpitt
    • Member since 04-20-2006, 11:19 AM
    • Posts 9
    Hi all

    I am trying to switch from PSP to ASP and im finding it very frustrating to do anything programatically without usign some of the tools available. For example accessing data without using gridview etc.

    I have spent days trying to figure this out, and read a few books that touch on the fact that its possible without actually explaining how to use the dataset for anything other than viewing data. All i really want to do is stick the data in some variable so that I can then do whatever I please with it.

    Heres an example of something I am trying to work out using the RSStoolkit.

    public partial class scenario4 : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    //From the RSStoolkit
    GenericRssChannel c = GenericRssChannel.LoadChannel("http://someRSSfeed");

    /*so here i want to use the data in "c"
    example:
    pleaseLetMeGetTheData = c[link];
    OR however im meant to access this...
    Dataset test = new dataset();
    test = c.SelectItems(); ?? aghhhhhhh
    //cannot implicitly convert blah blah blah.......
    */

    //Commented because i dont want to use the Gridview
    //GridView1.DataSource = c.SelectItems();
    //GridView1.DataBind();

    }

    }

    So you can see my problem. Perhaps im just not very smart with this, but any help would be appreciated.

    Cheers

    Dirk
  • Re: Accessing data without the controls

    05-28-2006, 7:50 AM
    • Participant
      1,162 point Participant
    • rumbafum
    • Member since 10-13-2005, 9:41 AM
    • Lisboa
    • Posts 247

    Guess the method you're using c.SelectItems returns IEnumerable... DataSet doesn't implements IEnumerable that's the problem... (Cannot implicitly convert....)

    You could use an ArrayList to get data

    ArrayList arr = new ArrayList()

    arr = c.SelectItems();

    this should work...

  • Re: Accessing data without the controls

    05-29-2006, 1:43 AM
    • Member
      45 point Member
    • dirkpitt
    • Member since 04-20-2006, 11:19 AM
    • Posts 9
    Thanks for your reply.

    With the code you have just pasted, i get the following error.

    Error    1    Cannot implicitly convert type 'System.Collections.IEnumerable' to 'System.Collections.ArrayList'. An explicit conversion exists (are you missing a cast?)  

    Cheers

    Dirk

  • Re: Accessing data without the controls

    05-29-2006, 3:00 AM
    • Member
      45 point Member
    • dirkpitt
    • Member since 04-20-2006, 11:19 AM
    • Posts 9
    Im also trying to cast like this....

    ArrayList test = new ArrayList();
            test = (ArrayList)c.SelectItems();

    which it lets me do, although I have no idea how to get the items out of test still..
  • Re: Accessing data without the controls

    05-29-2006, 12:13 PM
    • Participant
      1,162 point Participant
    • rumbafum
    • Member since 10-13-2005, 9:41 AM
    • Lisboa
    • Posts 247

    yep i forgot the arraylist cast sorry ....

    now you have all data inside your ArrayList test... You can access all the array positions and check for data... You need to know what type of data c.SelectItems stores in your ArrayList... Don't you have any documentation about this?

  • Re: Accessing data without the controls

    05-29-2006, 11:21 PM
    • Member
      45 point Member
    • dirkpitt
    • Member since 04-20-2006, 11:19 AM
    • Posts 9
    Documentation is a bit thin..

    Lets say the data stored is a string. I hve attempted to cycle through the positions to output  data, but generally i just get something like

    GenericRSS.channel.ArrayList

    or similiar. I cant give the exact message because i dont have it in front of me at the moment.



  • Re: Accessing data without the controls

    05-30-2006, 7:16 AM
    • Participant
      1,162 point Participant
    • rumbafum
    • Member since 10-13-2005, 9:41 AM
    • Lisboa
    • Posts 247

    I was seeing the RssToolkit and the method you're using c.SelectItems can return an ArrayList and in each of the arraylist position is a RssElementCustomTypeDescriptor object... Try to use this object properties to get the attributes values and stuff... So do the same i told you but getting data from the array to objects like this

    ArrayList arr = new ArrayList();

    arr = c.SelectItems();

    RssElementCustomTypeDescriptor rssElement = (RssElementCustomTypeDescriptor)arr[0];

    Try this don't know if it works thow

  • Re: Accessing data without the controls

    05-31-2006, 6:55 AM
    • Member
      45 point Member
    • dirkpitt
    • Member since 04-20-2006, 11:19 AM
    • Posts 9
    Thanks for responding, 5 days, 2 forums, emailed the author and still no joy.. :(

    Is it because I am trying to do something abnormal, I would have thought this very common?

    Error    1    'RssToolkit.RssElementCustomTypeDescriptor' is inaccessible due to its protection level   
  • Re: Accessing data without the controls

    06-02-2006, 9:14 AM
    • Participant
      885 point Participant
    • pettrer
    • Member since 02-08-2006, 9:08 AM
    • Stockholm, Sweden
    • Posts 323

    Hi there,

    I couldn't agree with you more regarding the lack of documentation.

    Rather than digging into your coding problem, let me tell you what I came up with. In this case, I retrieve one variable from a db and put it in a .aspx page. (VWD Express, VB)

    Protected

    Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    TidpunktHiddenField.Value = DateTime.Now

    Dim serie = "A"

    If Page.IsPostBack Then serie = SerieDropDownList.SelectedValue 'serie sätts

    If Not Page.IsPostBack Then serie = "A"

    Dim conn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("wizzyConnectionString").ConnectionString)

    Dim cmd As SqlCommand = New SqlCommand("SELECT TOP 1 vnr from products WHERE [fid]=1 AND [serie] = '" & serie & "' ORDER BY vnr DESC", conn)

    conn.Open()

    Dim id As String = cmd.ExecuteScalar

    conn.Close()

    VnrvardeLabel.Text = serie &

    ":" & id + 1

    ... etc (other pageload stuff).

    And in the .aspx page, simply insert the label defined in the code above:

    <

    asp:Label ID="VnrvardeLabel" runat="server" Style="z-index: 102; left: 120px; position: absolute;

    top: 120px"

    Text="" ToolTip="Numret som satts.">

    </asp:Label>

    There are other things like ExceuteScalar if you need more than one value, but others would know more about those than I do.

    Hope this helps!

    Pettrer

    Coding is a nine-to-five job: Nine PM to Five AM.
  • Re: Accessing data without the controls

    06-05-2006, 3:54 AM
    • Member
      45 point Member
    • dirkpitt
    • Member since 04-20-2006, 11:19 AM
    • Posts 9
    Thanks for your response, I have not looked at this problem again since my last post, I guess I have to assume the language doesnt cater that well to anything other than spoon feeding, or there is just  no one around who knows how it really works properly due to lack of documentation about anything other than simple control operation.

    Thanks for your reply, Execute scalar looks like it may help if I was querying a database.

    If anyone else out there can shed some light on what seems like a very simple request, then feel free to throw in your five cents. 

    Thanks again

    Dirk


  • Re: Accessing data without the controls

    08-19-2006, 10:23 PM
    • Member
      132 point Member
    • wsmonroe
    • Member since 04-11-2004, 6:16 AM
    • Posts 56
    Hi,

    I started using RSSToolkit tonight and ran into the same problem. I figured out how to get it working. It's done as follows (this is using VB, it's easily converted to C#):

     
    Dim Title as string
    Dim Descriptin as string
    Dim PostDate as string

    Dim Data as RssToolkit.GenericRssChannel
    Data = RssToolkit.GenericRssChannel.LoadChannel("http://www.phish.com/news/index.xml")

    'I'm not sure if the following line is needed or not.
    'I haven't tested without it yet.
    Data.SelectItems() For Each Item As RssToolkit.GenericRssElement In Data.Items
    'Now you can get the values for each item using
    'the attributes collection like so:
    Title = Item.Attributes("Title")
    Description = Item.Attributes("Description")
    PostDate = Item.Attributes("dc:date")

    'etc ... Next
     
    Hope this helps ....
    The Wheel is turning and you can't slow it down, can't let go and you can't hold on. You Can't go back, and you can't stand still, If the thunder don't get ya then the lightning will!
Page 1 of 1 (11 items)