我正在使用SQL Server 2014,我的问题是,当我单击“保存”按钮以保存Salary数据时,它提供了多个数据而不是一个数据,这是我的代码:
private void btnStart_Click(object sender, EventArgs e)
{
con.dataGet("Select * from EmpAttendance Where Year = '" +
cmbYear.Text + "' and Month = '" + cmbMonth.Text + "'");
DataTable dt = new DataTable();
con.sda.Fill(dt);
if(dt.Rows.Count > 0)
{
foreach(DataRow row in dt.Rows)
{
con.dataGet(@"SELECT ES.Salary, EA.WorkingDays,
EA.Presentdays, EA.LopDays FROM EmpAttendance EA INNER JOIN
EmpSalary ES ON EA.EmpId = ES.EmpId
Where EA.Year = '"+ cmbYear.Text +"' and EA.Month
= '"+ cmbMonth.Text +"' and EA.EmpId = '"+ dt.Rows[0]
["EmpId"].ToString() +"'");
DataTable dt1 = new DataTable();
con.sda.Fill(dt1);
salary = float.Parse(dt1.Rows[0]["Salary"].ToString());
workingDays = float.Parse(dt1.Rows[0]["WorkingDays"].ToString());
present = float.Parse(dt1.Rows[0]["PresentDays"].ToString());
lop = float.Parse(dt1.Rows[0]["LopDays"].ToString());
perDay = (salary / 12) / workingDays;
netSalary = (perDay * present) - (perDay * lop);
con.dataSend("INSERT INTO SalaryProcess (EmpId, Year,
Month, NetSalary) VALUES ('" + dt.Rows[0]["EmpId"].ToString() + "',
'" + cmbYear.Text + "', '" + cmbMonth.Text + "', '" + netSalary +
"')");
MessageBox.Show("Salary Generated!", "Message",
MessageBoxButtons.OK, MessageBoxIcon.Information);
LoadData();
}
}
}