Cannot perform '=' operation on System.String and System.Int32 [Resolved]

Posted by Self-Innovator under ASP.NET on 4/3/2012 | Points: 10 | Views : 5097 | Status : [Member] | Replies : 6
hi...
Can some one find me the solution... I am getting an error while i am bing the dataset value to datatable...ParenID is of type Char(3)..
SqlConnection cnn = new SqlConnection(Conn);
SqlCommand cmd = new SqlCommand("Select * From tbChildMenu", cnn);
SqlDataAdapter ada = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
ada.Fill(ds);
dt = ds.Tables[0];
DataRow[] dRowParent = dt.Select("ParentID="+ 0); //Error Line
foreach (DataRow dr in dRowParent)
{
menuBar.Items.Add(new MenuItem(dr["ParentID"].ToString(), dr["ChildID"].ToString()));
}
foreach (DataRow dr in dt.Select(""))
{
MenuItem mnu = new MenuItem(dr[""].ToString(), dr[""].ToString(), "", dr[""].ToString());
menuBar.FindItem(dr[""].ToString()).ChildItems.Add(mnu);
}


Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Rajni.Shekhar on: 4/3/2012 [Member] Bronze | Points: 50

Up
0
Down

Resolved
get all parent in loop in strParentID and pass it

string strParentID="M1"; 

DataRow[] dRowParent = dt.Select("ParentID=" + strParentID);



Thanks,
Rajni Shekhar

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 4/3/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
What are you trying to achieve here

DataRow[] dRowParent = dt.Select("ParentID="+ 0); //Error Line


Thank you for posting at Dotnetfunda
[Administrator]

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-Innovator on: 4/3/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi..vyuiswamb
I am trying to Bind the Menu Name in my parent Menu i've just refered to one article based on that i am trying to solve my problem...

http://www.codeproject.com/Tips/354696/Dynamically-populating-menu-items-from-the-databas
pls find me the soln..

Join Hands Change lives
Thanks & Regards
Straight Edge Society

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 4/3/2012 [Member] Bronze | Points: 25

Up
0
Down
did you maintain 0 for parent ID in your table? and please share error also.

Thanks,
Rajni Shekhar

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-Innovator on: 4/3/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi..thi sis my table structure...
I am getting an err in ... DataRow[] dRowParent = dt.Select("ParentID="+ 0); //Error Line
ChildID -CHAR(6)
ParentID-CHAR(2)
i am getting this below table as a dataset... so ls fin the soln
ChildID ParentID
M1Sub1 M1
M1Sub2 M1
M1Sub3 M1
M1Sub4 M1
M1Sub5 M1
M2Sub1 M2
M2Sub2 M2
M2Sub3 M2
M2Sub4 M2
M2Sub5 M2
M3Sub1 M3
M3Sub2 M3
M3Sub3 M3
M3Sub4 M3
M3Sub5 M3
M4Sub1 M4
M4Sub2 M4
M4Sub3 M4
M4Sub4 M4
M4Sub5 M4
M5Sub1 M5
M5Sub2 M5
M5Sub3 M5
M5Sub4 M5
M5Sub5 M5

Join Hands Change lives
Thanks & Regards
Straight Edge Society

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 4/3/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
What is the Datatype of ParentID in your database. please post a screenshot of your table tbChildMenu

Thank you for posting at Dotnetfunda
[Administrator]

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response