如何使用C#更新或编辑表中的特定列数据而不影响sql表中的其他列

时间:2019-05-06 12:24:11

标签: c# asp.net sql-server datatables sql-update

如何使用C#在不影响其他列sql的情况下更新表中的特定列? 我的实际问题是,当我尝试更新或编辑sql表中的数据时,它会影响整行的所有null,我该怎么办

我已使用更新查询从表单进行更新

我也是StackOverflow的新手

请帮助我

预先感谢

我尝试了多列更新其工作方式,但是我想要的确切是当我更新任何特定的列时,它仅在其他列保持相同数据的情况下也可以修改任何列而不会影响其他列

这是我的代码:

 private void UpdateUInfo_Click(object sender, EventArgs e)
        {
            //Reg.ConnectionString = @"Data Source = SRINIVASG-PC\SQLEXPRESS; Initial Catalog = WMSConnect; Integrated Security = True";//This is a connection string, is used to connect a database
            Reg.Open();
            SqlDataAdapter DelSUser = new SqlDataAdapter("UPDATE WMSRegform SET Name = '"+ FNameBox.Text +"', UserName = '"+ UNameBox.Text +"', MailAddr ='"+ MailBox.Text + "' , Paswrd = '" + PwdBox.Text + "', Contactinfo ='" + Contactinfo.Text + "'WHERE EmpID = " + EmpolyeeCode.Text +";", Reg);//This is a sql adapter class and it helps us to populate the data from Sql to c# like a bridge
            DataTable UpdUs = new DataTable();//I have create a datatable, it used populate a data
            DelSUser.Fill(UpdUs);
            dataGridView1.DataSource = UpdUs;
            Reg.Close();

            if (UpdUs.Rows.Count == 0)
            {
                MessageBox.Show("Mention User Has Been Updated Succesfully");

                clear();
            }

0 个答案:

没有答案