2
Contributors
1
Reply
7
Views
1 Year
Discussion Span
Last Post by Rakhmat_1
0

i'm not using mongoDB..

You can read the basic about connecting, get collection, store, and query here : https://code.msdn.microsoft.com/Getting-started-with-37dbd5bd

Example code :

Imports MongoDB.Bson 
Imports MongoDB.Dirver 
Imports Newtonsoft.Json 
Imports Newtonsoft.Json.Linq 

Module Module1 

    Sub Main() 

        Console.WriteLine("Connect...") 

        Dim mongo As MongoServer = MongoServer.Create() 
        mongo.Connect() 

        Console.WriteLine("Connected") 
        Console.WriteLine() 

        Dim db = mongo.GetDatabase("tutorial") 

        Using mongo.RequestStart(db) 
            Dim collection = db.GetCollection(Of BsonDocument)("books") 

            Dim book As BsonDocument = New BsonDocument() _ 
                .Add("_id", BsonValue.Create(BsonType.ObjectId)) _ 
                .Add("author", "Ernest Hemingway") _ 
                .Add("title", "For Whom the Bell Tolls") 

            collection.Insert(book) 

            Dim query = New QueryDocument("author", "Ernest Hemingway") 

            For Each item As BsonDocument In collection.Find(query) 
                Dim author As BsonElement = item.GetElement("author") 
                Dim title = item.GetElement("title") 

                Console.WriteLine("Author: {0}, Title: {1}", author.Value, title.Value) 

                For Each element As BsonElement In item.Elements 
                    Console.WriteLine("Name: {0}, Value: {1}", element.Name, element.Value) 
                Next 
            Next 
        End Using 

        Console.WriteLine() 
        Console.Read() 

        mongo.Disconnect 
    End Sub 

End Module

if you can display query result.. then convert/store it as datatable.

this's just an example how to bind datagrid, you have to make your own datatable based on your mongodb query.

Private Sub BindDataGridView()
    Dim dt As New DataTable()
    dt.Columns.AddRange(New DataColumn(2) {New DataColumn("Id", GetType(Integer)), New DataColumn("Name", GetType(String)), New DataColumn("Country", GetType(String))})
    dt.Rows.Add(1, "John Hammond", "United States")
    dt.Rows.Add(2, "Mudassar Khan", "India")
    dt.Rows.Add(3, "Suzanne Mathews", "France")
    dt.Rows.Add(4, "Robert Schidner", "Russia")
    Me.dataGridView1.DataSource = dt
End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.