I want to create code where if for example the dropdown list is = to linemen then his monthly salary is = 6000 and I want this to be put into monthly salary column in my database.
Here is the code - with this code I get error in monthlysalary parameters saying
use of unassigned local variable total
Code:
float total;
if (Designation.SelectedValue == "Linemen")
{
total = 4000;
}
if (Designation.SelectedValue == "Manager")
{
total = 6000;
}
if (Designation.SelectedValue == "Boss")
{
total = 8000;
}
string emp = datapayemp.SelectedRow.Cells[1].Text;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ConnectionString);
string command = "INSERT INTO PAYROLL(RegEmpID, MonthlySalary) VALUES (@RegEmpID, @MonthlySalary)";
SqlCommand cmd = new SqlCommand(command, con);
cmd.Parameters.AddWithValue("@RegEmpID", emp);
cmd.Parameters.AddWithValue("@MonthlySalary",total);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
finally
{
con.Close();
}