Esempio n. 1
0
        private void cmdInster_Click(object sender, EventArgs e)
        {
            //增加文档内容
            //1. check link MongoDB
            //2. insert
            lblMsg.Text      = "";
            lblMsg.ForeColor = System.Drawing.Color.Blue;
            if (isFirst)
            {
                MessageBox.Show("请先初始化连接 MongoDB,再进行 增加文档内容 作业", "ERROR");
            }
            else
            {
                Model.AccountModel account = new Model.AccountModel();
                account.value = txtValue.Text;

                client.Insert("name", txtValue.Text);


                lblMsg.Text = "Insert 成功。";

                Model.AccountModel ress = client.Find(MongoDB.Driver.Builders.Query <Model.AccountModel> .EQ(xx => xx.name, account.value));

                dataGridView1.Rows.Add(ress.name, ress.id);

                txtValue.Text = "";
                txtNewV.Text  = "";
            }
        }
Esempio n. 2
0
        private void cmdUpdate_Click(object sender, EventArgs e)
        {
            //变更文档内容
            lblMsg.Text      = "";
            lblMsg.ForeColor = System.Drawing.Color.Blue;
            if (isFirst)
            {
                MessageBox.Show("请先初始化连接 MongoDB,再进行 增加文档内容 作业", "Error:");
            }
            else
            {
                try
                {
                    client.Update("name", txtValue.Text, txtNewV.Text.ToString());
                    lblMsg.Text = "Update 成功。";

                    Model.AccountModel account = new Model.AccountModel();

                    account.value = txtNewV.Text;
                    Model.AccountModel ress = client.Find(MongoDB.Driver.Builders.Query <Model.AccountModel> .EQ(xx => xx.name, account.value));


                    dataGridView1.Rows.Add(ress.name, ress.id);

                    txtValue.Text = "";
                    txtNewV.Text  = "";
                }
                catch (Exception)
                {
                    lblMsg.Text      = "沒有找到值:" + txtValue.Text;
                    lblMsg.ForeColor = System.Drawing.Color.Red;
                }
            }
        }