I have a question about MongoDB and C #, I need to filter the searches by an employee's name, that is, you put your name in a text box and if it exists the data is displayed in DataGrid
.
These are my advances:
public class Entity
{
public ObjectId Id { get; set; }
public string nombre { get; set; }
public string apepat { get; set; }
public string apemat { get; set; }
}
private void button1_Click(object sender, EventArgs e)
{
var connectionString = "mongodb://localhost";
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase("base_datos");
var collection = database.GetCollection<Entity>("empleados");
BindingList<Entity> doclist = new BindingList<Entity>();
foreach (var deger in collection.Find("nombre", textBox1.Text))
{
doclist.Add(deger);
string[] row0 = new string[] { deger.Id.ToString() };
string[] row2 = new string[] { deger.nombre.ToString() };
string[] row3 = new string[] { deger.apepat.ToString() };
string[] row4 = new string[] { deger.apemat.ToString() };
Application.DoEvents();
dataGridView1.DataSource = doclist;
}
}