Share via


Operator '+' cannot be applied to operands of type 'string' and 'method group'

Question

Friday, May 21, 2010 4:28 PM

        int[] AdminUsers;
        AdminUsers = new int[10]; 

 
        for (int i = 0; i < cnt; i++)
        {

            int tempVal2 = AdminUsers[cnt];

            string strSQL = "insert into UserAccess (UserID, SystemID, SystemVersionID) " +
            "values (" + Convert.ToString(tempVal2) + "," + ddSelect.SelectedItem.ToString + ",1)";

 

Error: Operator '+' cannot be applied to operands of type 'string' and 'method group'

It doesn't like the + "Convert.ToString(tempVal2)"  Any ideas?

All replies (6)

Friday, May 21, 2010 6:31 PM ✅Answered

If this is your actual code, then you need to fix ddSelect.SelectedItem.ToString().

If this doesn't fix it, then try tempVal2.ToString(). 


Saturday, May 22, 2010 3:42 AM ✅Answered

i would rather ask you to go for Parameterized queries -

http://www.aspnet101.com/2007/03/parameterized-queries-in-asp-net/


Friday, May 21, 2010 6:46 PM

Just type ToString() instead of ToString.  


Monday, May 24, 2010 1:36 AM

You just need to mark it with tempVal2.ToString().


Monday, May 24, 2010 1:52 AM

Try this

string strSQL = "insert into UserAccess (UserID, SystemID, SystemVersionID) values (" + Convert.ToString(tempVal2) + "," + Convert.ToString(ddSelect.SelectedItem) + ",1)";

Monday, May 24, 2010 2:11 AM

I hope no one posts a page to your server where ddlSelect.Selecteditem is

1,1);drop table UserAccess; --

You may want to think about the lesson contained in http://xkcd.com/327/