litedb 查看查询结果

litedb see results from query

我想知道如何在加载表单时在控制台或多行文本框中查看来自 LiteDB 的文本格式的数据库结果。这是我目前所掌握的,但没有 return 信息。

 private void DisplayData_Load(object sender, EventArgs e)
                    {
                        using (var db = new LiteDatabase(@"C:\Temp\MyData.db"))
                        {
                        // Get a collection (or create, if doesn't exist)
                            var col = db.GetCollection<DataBase>("data");

                        // Create your new customer instance
                           var results = col.FindAll();
                           Console.WriteLine(results);
                        }
                    }

我想我找到了答案的一个版本。此代码将数据显示到组合框、控制台输出或作为文本框的文本...

public class DataBase
    {
        [BsonId]
        public string GetSetVariable { get; set; }
    }

private void DisplayData_Load(object sender, EventArgs e)
{
    using (var db = new LiteDatabase(@"C:\Temp\MyData.db"))
    {
        // Get a collection (or create, if doesn't exist)
        var col = db.GetCollection<DataBase>("collection_name");

        // Enter data into the database
        var incomingData = new Database
        { 
            GetSetvariable = "This is output text."
        };

        // Create unique index in Name field
        col.EnsureIndex(x => x.GetSetVariable, true);

        // Insert new customer document (Id will be auto-incremented)
        col.Insert(incomingData);

        // Update a document inside a collection
        incomingData.GetSetVariable = "Updated Text Record";
        col.Update(incomingData);

        // Create a query
        var results = col.FindAll();

        // To display ALL columns of 'results' in a combo box.
        foreach (var finding in results)
        {
            var variable = finding.GetSetVariable;
            comboBox1.Items.Add(variable);
            Console.WriteLine(variable);
        }

        // To display one record of 'results' to a text box.
        var query = col.FindById(1);
        var variable = query.GetSetVariable;
        textBox1.Text = variable;
        Console.WriteLine(variable);
    }
}