I am trying to convert a field from a string to an int, then pass it to a query using tableadapters.
I have the following function:
protected String countResponses(String value)
{
String input = value.ToString();
int fordb = Int32.Parse(input);
FrontendTableAdapters.ForumTableAdapter ta = new FrontendTableAdapters.ForumTableAdapter();
DataTable table = ta.CountPosts(value);
if (table.Rows.Count > 0)
{
return table.Rows[0].ItemArray[1].ToString();
}
else
{
return "Unknown";
}
}
It is working greate up to putting it in CountPosts() where I get the following error:
Error 4
Cannot implicitly convert type ‘object’ to ‘System.Data.DataTable’. An explicit conversion exists (are you missing a cast?) C:\Users\Dave\Desktop\WebApps\Figmentville\Figmentville\yoursay\Default.aspx.cs 49 31
I think this is because it is looking for an int. But haven’t I already converted it to an int?
Thanks
Dave.
Since we don’t know what
ForumTableAdapteris, it isn’t clear whatCountPostsreturns, but if this is actually returning aDataTable(but typed asobject) it sounds like you just want:but then, I also expect
Count...to return anint…Also; minor point: the line
String input = value.ToString();is both unnecessary and potentially a cause of anullbug (but not in this case) – you should be able to just use:(and remove the
inputvariable completely)