Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
using MongoDB.Driver.Linq;

public partial class _Default : System.Web.UI.Page
{
    MongoCollection collection;
    MongoDatabase database;
    string s1;
    protected void Page_Load(object sender, EventArgs e)
    {
        database = new MongoClient("mongodb://avant:avant@127.0.0.1:27017").GetServer().GetDatabase("demo1");//database
        collection = database.GetCollection<ques>("que");

        s1 = Request.QueryString["t1"];
        Response.Write("<h1>");
        Response.Write(s1);

    }
    class ques
    {
        public ObjectId id { get; set; }
        public string question { get; set; }
        public string category { get; set; }
        public List <ans> answer { get; set; }
        public string user { get; set; }
       
    }

    class ans
    {
        public ObjectId id { get; set; }
        public string answer { get; set; }
        public string score { get; set; }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

         collection.Update(Query.EQ("question", " What is an object?  "), Update.SetWrapped<ans>("answer", new ans { answer = TextBox1.Text, score = "5" }));

          }  
}
Posted
Comments
ZurdoDev 29-Apr-14 15:34pm    
Where are you stuck?
Member 10618067 29-Apr-14 16:17pm    
i am creating a final year college project.i am creating a discussion form..the problem is that in my project one question have many answer..but i am inserting only one answer in a question..how to insert second and third answer in to the same question..plz help me sir.
ZurdoDev 29-Apr-14 16:20pm    
I don't understand where you are stuck or how we can help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900