...

View Full Version : DataItem in C#



Cipher
10-23-2005, 03:00 PM
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'

allida77
10-23-2005, 07:47 PM
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/CheatSheetCastingNET.asp



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum