0

MongoDB for C#, I started following their tutorial but the compile error I get is on this line:

http://www.mongodb.org/display/DOCS/CSharp+Driver+Quickstart

 var update = Update.Set("Name", "Harry");

saying

System.Windows.Forms.Control.Update()' is a 'method', which is not valid in the given context.

The only difference I see is that they have used a Console Application but I created a C#WinForms applications and pasted their code inside a button click .

3
  • What is the rest of the code? where did you take it from. Sounds like you should qualify Update, but it's hard to tell with what you have here. Commented May 9, 2012 at 13:53
  • @pms1969 : Oh sorry, forgot to paste the link to the code..post updated. Commented May 9, 2012 at 13:54
  • the bottom of that tutorial has a link to a forum hosted by the guys who made the tutorial for the specific purpose of being able to ask them questions about it :P though youll get a wider range of answers here, probably faster too i guess Commented May 9, 2012 at 13:59

2 Answers 2

4

Update is simply ambiguous in the context you are using the call. You need to qualify the Update statement to include the namespace it is in.

var update = MongoDB.Driver.Builders.Update.Set("Name", "Harry");

This will probably get annoying, so you can also create an alias in your header.

using U = MongoDB.Driver.Builders.Update;

Then, you can change your statement to be this:

var update = U.Set("Name", "Harry");
Sign up to request clarification or add additional context in comments.

Comments

2

I guess your c#WinForms contains an method called Update, which c# tries to access instead of the MongoDB one. Have you checked that you're imported everything needed and that your accessing the right Object?

1 Comment

Stuck to Craigs answer detailed information on howto resolve it. (I'm just a java boy)

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.