Dear All,
I am trying to convert a Label Text string into Integer datatype and store it in SQL Database. I had it implemented and running in my program just fine before this morning. But then I had to copy paste whole project from old .cs to new .cs, and now it is throwing error.
My code is:
protected void btnUpdate_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(vGrid);
using (SqlConnection con = new SqlConnection("Data Source=MEHDI-PC\\SQLEXPRESS;Initial Catalog=PIMS;Integrated Security=True"))
{
using (SqlCommand cmd = new SqlCommand())
{
string sql = "UPDATE dbo.Documents SET Ref = @Ref, Subject = @Subject, Src = @Src, Dst = @Dst, Medium = @Medium, Date_Printed = @Date_Printed, Date_Received = @Date_Received, Document_Type = @Document_Type,Action_Required = @Action_Required, Due_Date = @Due_Date, Actual_Date = @Actual_Date, Content = @Content, Tag = @Tag, Issue_No = @Issue_No, Attachment = @Attachment, Notes = @Notes, Assigned_To = @Assigned_to, Reply_Ref = @Reply_Ref, Priority = @Priority, Status = @Status, Response = @Response WHERE DocumentsID = @DocumentsID ";
cmd.Connection = con;
cmd.CommandText = sql;
cmd.Parameters.Add(new SqlParameter("@Ref", txtRef.Text));
cmd.Parameters.Add(new SqlParameter("@Subject", txtSubject.Text));
cmd.Parameters.Add(new SqlParameter("@Src", ddlSource.Text));
cmd.Parameters.Add(new SqlParameter("@Dst", ddlDestination.Text));
cmd.Parameters.Add(new SqlParameter("@Medium", ddlMedium.Text));
cmd.Parameters.Add(new SqlParameter("@Date_Printed", txtDatePrinted.Text == "" ? DBNull.Value : (object)txtDatePrinted.Text));
cmd.Parameters.Add(new SqlParameter("@Date_Received", txtDateReceived.Text == "" ? DBNull.Value : (object)txtDateReceived.Text));
cmd.Parameters.Add(new SqlParameter("@Document_Type", ddlDocumentType.Text));
cmd.Parameters.Add(new SqlParameter("@Action_Required", cbxAction.Checked));
cmd.Parameters.Add(new SqlParameter("@Due_Date", txtDueDate.Text == "" ? DBNull.Value : (object)txtDueDate.Text));
cmd.Parameters.Add(new SqlParameter("@Actual_Date", txtActualDate.Text == "" ? DBNull.Value : (object)txtActualDate.Text));
cmd.Parameters.Add(new SqlParameter("@Content", txtContent.Text));
cmd.Parameters.Add(new SqlParameter("@Tag", txtTag.Text));
cmd.Parameters.Add(new SqlParameter("@Issue_No", txtIssue.Text));
cmd.Parameters.Add(new SqlParameter("@Attachment", txtAttachment.Text));
cmd.Parameters.Add(new SqlParameter("@Notes", txtNotes.Text));
cmd.Parameters.Add(new SqlParameter("@Assigned_To", ddlAssignedTo.Text));
cmd.Parameters.Add(new SqlParameter("@Reply_Ref", txtReplyRef.Text));
cmd.Parameters.Add(new SqlParameter("@Priority", ddlPriority.Text));
cmd.Parameters.Add(new SqlParameter("@Status", ddlStatus.Text));
cmd.Parameters.Add(new SqlParameter("@Response", ddlResponse.Text));
cmd.Parameters.Add(new SqlParameter("@DocumentsID", Int32.Parse(lblSet.Text)));
con.Open();
cmd.ExecuteNonQuery();
}
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
}
It is throwing an error on the following Line:
cmd.Parameters.Add(new SqlParameter("@DocumentsID", Int32.Parse(lblSet.Text)));
Error Message:
Input string was not in a correct format.
Any help would be much appreciated.
Kind regards.