Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot assign because it is a method group

Status
Not open for further replies.

mpnut

MIS
Aug 27, 2003
242
I am very very new to C# (and programming in general) so forgive me if I stumble a little. Here is my code:

int ticket_locked_by()
{
int lockedby;
int mine;

string sqlock = @"SELECT ti_locked_by FROM tickets WHERE ti_id = $id";
sqlock = sqlock.Replace("$id", Convert.ToString(id));
lockedby = Convert.ToInt32(sqlock);
mine = security.user.usid;

if (lockedby == mine)

return 1;

else

return 0;

}


Then I try to get the returned value (either 1 or 0) with:

void Page_Load(Object sender, EventArgs e)
{
if (ticket_locked_by = 1)
{
sub.Value = "LOCKED";
}

else

{
sub.Value = "Unlocked";
}
}
But I get the "cannot assign to 'ticket_locked_by' because it is a method group. I have done some research and I see that you can't assign value to a method group. So how/what can I get ticket_locked_by to be a value or 1 or 0?
 
First, because ticket_locked_by is a method, you have to use the parentheses (empty if no parameters) when calling it.

Thus it should be: ticket_locked_by()

Also, '=' means assign the value on the right side to the attribute on the left. '==' means an equality check, so you need '=='. So you will have:

Code:
if (ticket_locked_by() == 1)
{
   sub.Value = "LOCKED";
}
..

|| ABC
 
Thank you so much. This has been driving me crazy for the last couple days. I am very greatful to you. And thank you for explaining why it happens and not just a fix. Teaching a man to fish. Brilliant!
 
C# is very stringent about naming conventions and syntax (whereas vb is very forgiving). if there are no paranthesis then c# is expecting a property [tt]object Foo {get{ return something;}}[/tt]. if there are paranthesis then it's looking for a method [tt]object Foo(){ return something;}[/tt]. in fact properties are just syntatic sugar around methods... but i digress.

also as a side note. And I only mention this because you said you are new to c#. there is a much better way to declare sql statements to prevent sql injection attacks.
use parameterized queries.
your sql string above would read [tt]string sqlock = @"SELECT ti_locked_by FROM tickets WHERE ti_id = @id";
[/tt]. once this is assigned to a command add a parameter for id with the supplied value and your done. for more info on the subject google ado.net and parameterized queries for c#.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top