更新选定的Datagrid视图行-Visual Studio

时间:2019-05-30 09:26:54

标签: c# sql-server database sql-update

我一直在为我的父亲建立工资/会计程序,以节省他使用Excel的时间和精力,不妨回到笔和纸上来。我已经准备好一切,并且以原始的方式是原始的,但是用户友好,但是似乎仍然无法正确获取“更新查询”。我确实有一个Azure帐户,该帐户当前正在用于“云数据库”访问。

我尝试了几种方法:

//This is not the complete codes I have used.
newDataRow.Cells[0].Value = regYTD.Text;
string query = "UPDATE employeeInfo SET..."
/////////////////////////////////////////////

private void stubDbBtnUpdate_Click(object sender, EventArgs e)
{     
      //This is what I am currently using. 
      con.Open(); 
      string query = "UPDATE EmployeeInfo SET [Address Line 1] = '" + employeeAddress1.Text + "', [Address Line 2] = '" + employeeAddress2.Text + "', [City] = '" + employeeCity.Text + "', " +
                       "[State] = '" + employeeState.Text + "', [Zip] = '" + employeeZip.Text + "', [Phone] = '" + employeePhone.Text + "', " +
                       "[SSN] = '" + employeeSSN.Text + "', [Regular Earnings-YTD] = '" + regYTD.Text + "', " +
                       "[Overtime Earnings-YTD] = '" + ovrYTD.Text + "', [Total Earnings-YTD] = '" + totYTD.Text + "', [Federal-YTD] = '" + fedYTD.Text + "', " +
                       "[State-YTD] = '" + stYTD.Text + "', [Social-YTD] = '" + ssYTD.Text + "', [MediCare-YTD] = '" + medCareYTD.Text + "', " +
                       "[Total Deductions-YTD] = '" + deduYTD.Text + "',[Net Pay-YTD] = '" + netYTD.Text + "' ";
      SqlDataAdapter dataAdapter = new SqlDataAdapter(query, con);
      dataAdapter.SelectCommand.ExecuteNonQuery();
      con.Close();
 }

到目前为止,他们没有给我一个错误,要么说语法不正确,要么输入错误,但是使用newDataRow.Cell仅在本地更新所需的单元格。这段代码可以正确更新(直到云),但也可以使用相同的[Name]更新其余单元。

0 个答案:

没有答案