So i just got into programming and into C# & noSQL databases.
I'm currently working on a small program, that shows the data of a MongoDB database on an ASP.NET webapplication. Im stuck with connecting to my local database.
The data needs to be stored in lblMotherboard: This is my code. builder.aspx:
<asp:Label ID="lblMotherboard" runat="server" Text=""></asp:Label>
builder.aspx.cs:
using MongoDB.Bson;
using MongoDB.Driver;
public void showMobos_Click(object sender, EventArgs e)
{
var name = "";
var connectionString = "mongodb://localhost:27017/";
var mongoClient = new MongoClient(connectionString);
MongoServer server = mongoClient.GetServer();
MongoDatabase database = server.GetDatabase("mydb");
MongoCollection<Post> mobos = database.GetCollection<Post>("moederborden");
foreach (Post parts in mobos.FindAll())
{
name = name + " " + parts.Aanbieder + " " + parts.ProductNaam;
}
lblMotherboard.Text = name;
}
showMobos_Click starts when a button is clicked. It doesn't print any data. What is going wrong?
Sample document:
{
"_id" : ObjectId("54a287ef0d0a7f888510d14e"),
"Aanbieder" : "Coolblue",
"Productlink" : "http://computerstore.nl/product/470130/category-208983/asrock-z97-extreme6.html",
"Productnaam" : "Asus H97-Pro Gamer",
"Prijs" : "129,-",
"Socket" : "1150"
}
Post.class:
public class Post
{
public ObjectId _id { get; set; }
public String Aanbieder { get; set; }
public String Productlink { get; set; }
public String Productnaam { get; set; }
public decimal Prijs { get; set; }
public int Socket { get; set; }
}