Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: DataItem in C#

  1. #1
    Regular Coder Cipher's Avatar
    Join Date
    Dec 2004
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DataItem in C#

    well this's my first time in C#, i'm currently using VB.NET, so how can i get items from DataSet, here's the VB Code:

    Dim curCatAs String
    For i = 0 To dstTopics.Tables(0).Rows.Count - 1
    curCat = dstTopics.Tables(0).Rows(i).Item("CategoryName")
    Next


    i tried this in C# like this but it didnt work:

    string curCat;
    for (i = 0; i < dstTopics.Tables[0].Rows.Count; i++) {
    curCat = dstTopics.Tables[0].Rows[i].ItemArray["CategoryName"];
    //also tried this:
    curCat = dstTopics.Tables[0].Rows[i].ItemArray[0];
    }


    Here's the error that appears
    Cannot implicitly convert type 'object' to 'string'
    i need a creative atmosphere

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Cincinnati, OH
    Posts
    545
    Thanks
    0
    Thanked 0 Times in 0 Posts
    c# is strongly typed language thus your error.

    change this line:
    curCat = dstTopics.Tables[0].Rows[i].ItemArray[0];

    to:
    curCat = (string) dstTopics.Tables[0].Rows[i].ItemArray[0];


    Here is some info on casting in .net (c# and vb)
    http://www.codeproject.com/dotnet/Ch...CastingNET.asp
    does this sig match?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •