Hi forum, I need some help! Ive converted a script from VB to C#. Come across the: 'System.Data.DataSet.Tables' is a 'property' but is used like a 'method' .Here attaching the code.
public
void PopulateMenu(){
System.Data.
DataSet dst = GetMenuData(); foreach (System.Data.DataRow masterRow in dst.Tables("tblModules").Rows()) // ERROR 'System.Data.DataSet.Tables' is a 'property' but is used like a 'method'{
MenuItem masterItem = new MenuItem(masterRow("ModuleName").ToString()); //Error 2 'masterRow' is a 'variable' but is used like a 'method'Menu1.Items.Add(masterItem);
foreach (System.Data.DataRow childRow in masterRow.GetChildRows("Children")){
MenuItem childItem = new MenuItem(childRow("FormName").ToString()); //Error 3 'childRow' is a 'variable' but is used like a 'method'masterItem.ChildItems.Add(childItem);
}
}
}
public System.Data.DataSet GetMenuData(){
System.Data.SqlClient.
SqlConnection con = new System.Data.SqlClient.SqlConnection(connectionString);System.Data.SqlClient.
SqlDataAdapter dadCats = new System.Data.SqlClient.SqlDataAdapter("SELECT * FROM tblModules", con);System.Data.SqlClient.
SqlDataAdapter dadProducts = new System.Data.SqlClient.SqlDataAdapter("SELECT * FROM tblForms", con);System.Data.
DataSet dst = new System.Data.DataSet();dadCats.Fill(dst,
"Module");dadProducts.Fill(dst,
"Form");dst.Relations.Add(
"Children", dst.Tables("Module").Columns("ModuleID"), dst.Tables("Form").Columns("ModuleID")); //Error 4 'System.Data.DataSet.Tables' is a 'property' but is used like a 'method' //Error 5 'System.Data.DataSet.Tables' is a 'property' but is used like a 'method' return dst;}
adithya dugyalaPosted Sep 1, 2008, 5:02 AM
Thanu Manish Dwivedi
can u help me in menuitem.navigateurl
how i should write the code help me
Blocked AccountPosted Sep 1, 2008, 6:19 AM
Hi Aditya,
U can do this by using this way
foreach (System.Data.DataRow childRow in masterRow.GetChildRows("Children"))
{
MenuItem childItem = new MenuItem(childRow["FormName"].ToString());
ChildItem.NavigateUrl=”Any Path which u want to give.”
masterItem.ChildItems.Add(childItem);
}
Blocked AccountPosted Sep 1, 2008, 4:17 AM
Hi,
Wherever u are getting the error in your code change the small bracket "(" into big bracket " [ ". after doing this your error will be removed.
for ex.
dst.Tables("tblModules") convert like that dst.Tables["tblModules"]
Happy Coding!!