Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在添加/保存之前,检查db中是否已经存在值并绑定dgv_C#_Datagridview - Fatal编程技术网

C# 在添加/保存之前,检查db中是否已经存在值并绑定dgv

C# 在添加/保存之前,检查db中是否已经存在值并绑定dgv,c#,datagridview,C#,Datagridview,我有一个绑定的datagridview,我想在插入用户名之前检查该用户名是否已经存在于我的数据库中。我通过文本框向dgv和数据库插入值。提前谢谢 private void user1BindingNavigatorSaveItem_Click(object sender, EventArgs e) { this.Validate(); this.user1BindingSource2.EndEdit(); this.tableAda

我有一个绑定的datagridview,我想在插入用户名之前检查该用户名是否已经存在于我的数据库中。我通过文本框向dgv和数据库插入值。提前谢谢

    private void user1BindingNavigatorSaveItem_Click(object sender, EventArgs e)
    {
        this.Validate();
        this.user1BindingSource2.EndEdit();
        this.tableAdapterManager2.UpdateAll(this.databasDataSet);

    }

    private void Form2_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'databasDataSet.user1' table. You can move, or remove it, as needed.
        this.user1TableAdapter2.Fill(this.databasDataSet.user1);

        user1DataGridView.Columns[0].Visible = false;
        passwordTextBox.PasswordChar ='*';

    }

    private void add_new_button_Click(object sender, EventArgs e)
    {

            this.user1BindingSource2.AddNew();

    }

    private void save_button_Click(object sender, EventArgs e)
    {


        this.Validate();
        this.user1BindingSource2.EndEdit();
        this.tableAdapterManager2.UpdateAll(this.databasDataSet);
    }




    private void delete_button_Click(object sender, EventArgs e)
    {
        this.user1BindingSource2.RemoveCurrent();

    }

要验证服务器端的任何内容(在您的案例中是否存在用户名),有
CustomValidator
控件。将其添加到您的页面,并将其附加到您的用户名
文本框
。然后将验证代码放入
ServerValidate
事件处理程序