3
Reply

EditStaff got input string problem

Cj Mah

Cj Mah

Dec 29 2015 7:19 AM
357
i got the error message: Input string was not in a correct format. I cannot find the error.
 
 
string staffId = null;
SqlConnection conn = null;
SqlCommand cmd = null;
string connectionString = null;
protected void btnSubmit_Click(object sender, EventArgs e)
{
connectionString = ConfigurationManager.ConnectionStrings["FacilityCS"].ConnectionString;
conn = new SqlConnection(connectionString);
string sql = "UPDATE Staff SET StaffId=@staffId, Password=@password, StaffName=@staffName,";
sql+=" Email=@email, PhoneNo=@phoneNo, Title=@title, Role=@role";
try
{
cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@staffId", tbStaffId.Text);
cmd.Parameters.AddWithValue("@password", tbPassword.Text);
cmd.Parameters.AddWithValue("@staffName", tbStaffName.Text);
cmd.Parameters.AddWithValue("@email", tbEmail.Text);
cmd.Parameters.AddWithValue("@phoneNo", tbPhoneNo.Text);
cmd.Parameters.AddWithValue("@title", Convert.ToInt32(ddlTitle.SelectedValue));
cmd.Parameters.AddWithValue("@role", Convert.ToInt32(rbRole.SelectedValue));
conn.Open();
int row = cmd.ExecuteNonQuery();
if(row>0)
{
lblOutput.Text = "Record Updated successfully";
}
}
catch(Exception ex)
{
lblOutput.Text = "Error Message: " + ex.Message;
}
finally
{
if (conn != null)
conn.Close();
}
}
 

Answers (3)