Bohn
Bohn

Reputation: 26919

Update() not working in MongoDB

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 .

Upvotes: 0

Views: 653

Answers (2)

Craig Wilson
Craig Wilson

Reputation: 12624

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");

Upvotes: 4

philnate
philnate

Reputation: 1506

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?

Upvotes: 2

Related Questions