为什么我得到这个问题“附加信息:找不到对象”设备“,因为它不存在。”

时间:2015-06-22 19:48:18

标签: c#

我尝试编写设备管理工具,但我无法将新信息保存到数据库中。我的部分代码如下。非常感谢。

private void button1_Click(object sender, EventArgs e)
{
        if (checkValidDate() == 1)
        {

            if (MessageBox.Show("Location: " + comboBox1Selected + Environment.NewLine +
                              "Device Type: " + comboBox2Selected + Environment.NewLine +
                              "Device ID: " + textBox1.Text + Environment.NewLine +
                              "Serial Number: " + textBox2.Text + Environment.NewLine +
                              "Warranty Exp Date: " + textBox3.Text + Environment.NewLine +
                              "Memo: " + textBox4.Text + Environment.NewLine +
                              "UserName: " + textBox5.Text + Environment.NewLine +
                              "Room Num: " + textBox6.Text, "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                // user clicked yes
                MessageBox.Show("3333333333");
                addToDataBase();
            }
            else
            {
                // user clicked no
            }
        }
        else
        {

        }
    }

private void button2_Click(object sender, EventArgs e)
{
    if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
    {
        // user clicked yes
    }
    else
    {
        // user clicked no
    }
}

1 个答案:

答案 0 :(得分:0)

if (checkValidDate() == 1)
{
    DialogResult result = MessageBox.Show("Do you want to save changes?", "Confirmation", MessageBoxButtons.YesNoCancel);
    if(result == DialogResult.Yes)
    { 
        //...write your code here that will save data to the database
    }
    else if (result == DialogResult.No)
    { 
        //...
    }
    else
    {
        //...
    }
}