任何人都可以帮助您如何从Mongodb获取数据并在Datagridview中显示该数据。在这里我尝试了这个。任何人都可以给出更好的答案
var ConnectionString = "mongodb://localhost";
var client = new MongoClient(connectionString);
// var server = client.GetServer();
var database = client.GetDatabase("testdb1");
var collection = database.GetCollection<Entity>("tablo1");
//var entity = collection.FindAll();
BindingList<Entity> doclist = new BindingList<Entity>();
foreach (var deger in collection.Find(doclist))
doclist.Add(deger);
//string[] row1 = new string[] { deger.deger1.ToString() };
//dataGridView1.Rows.Add(row1);
Application.DoEvents();
}
答案 0 :(得分:0)
尝试一下:
var connectionString = "mongodb://localhost";
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase("DB Name");
var collection = database.GetCollection<Class Name>("Table Name");
List<Class Name> list = await collection .Find(x => true).ToListAsync();
dataGridView1.DataSource = list