0

I have this function

public void Search(object sender, EventArgs e)
{  
  //I get the value form a query..
  int MachineNo=Convert.ToInt16(cmd2.ExecuteScalar());
}

i want to get the MachineNo from that function to this

 public void Edit(object sender, EventArgs e)
 {
    bool edit=modify(MachineNo,UserName)
 }
1
  • Are both methods inside the same class? Commented Sep 18, 2013 at 22:55

2 Answers 2

4

Change your Search function to:

public int Search(object sender, EventArgs e)
{  
   return Convert.ToInt16(cmd2.ExecuteScalar());
}

Then change Edit to:

 public void Edit(object sender, EventArgs e)
 {
    var MachineNo = Search(sender, e); 
    bool edit=modify(MachineNo,UserName)
 }

It's also not clear what UserName is in the Edit method, so make sure that's defined somewhere. Also, in your example, sender and e are not actually used in the Search method so those could be removed from the method signature and the call. If Search must match some delegate, you might have to create another Search method.

Sign up to request clarification or add additional context in comments.

5 Comments

beat me by 4 seconds ):
Why do we have to call Search in Edit? the logic doesn't make much sense although it does solve the OP's problem.
@KingKing - I'm assuming there's a lot more to Search that we don't see in this example (eg, the database connection work), thus it needs to be abstracted in its own method.
@MikeChristensen, what is the purpose of object sender, EventArgs e in the function?
@DonA - None that I can see. Perhaps its bound to an event handler and needs to match a certain delegate?
0

Have you tried changing the return type of your function?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.