0

我想知道如何在控制台中的 LiteDB 中以文本格式查看数据库的结果,或者在表单加载时查看多行文本框。这是我到目前为止所拥有的,但它不会返回信息。

 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);
                        }
                    }
4

1 回答 1

0

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

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);
    }
}
于 2017-04-14T14:58:51.277 回答