I'm currently trying to debug the return statement for my last line of code. I'm currently receiving a System.FormatExceptionError thrown there. I've been told that the return statement, as is currently, is attempting to accomplish 3 things. In order to know where the error is being thrown, I believe I need to execute those 3 things in separate return statements. Here's the code:
public int UpdateConnectionType(int connectionTypeID, string lastUpdatedBy, string connectionTypeDesc, bool isDisabled )
{
var sqlStatement = new StringBuilder();
sqlStatement.Append(" UPDATE dbo.ConnectionType");
sqlStatement.Append(" SET");
sqlStatement.Append(" LastUpdatedBy = @LastUpdatedBy, ");
sqlStatement.Append(" ConnectionTypeDesc = @ConnectionTypeDesc,");
sqlStatement.Append(" IsDisabled = @IsDisabled, ");
sqlStatement.Append(" LastUpdatedDate = GetDate() ");
sqlStatement.Append(" WHERE ");
sqlStatement.Append(" ConnectionTypeID = @ConnectionTypeID");
sqlStatement.Append(" SELECT @@Identity");
SqlCommand sqlCommand = new SqlCommand(sqlStatement.ToString());
var sqlParams = new List<SqlParameter>();
sqlParams.Add(new SqlParameter() { ParameterName = "@ConnectionTypeID", SqlDbType = SqlDbType.Int, Value = connectionTypeID });
sqlParams.Add(new SqlParameter(){ParameterName = "@IsDisabled", SqlDbType = SqlDbType.Bit, Value = isDisabled});
sqlParams.Add(new SqlParameter() {ParameterName = "@LastUpdatedBy", SqlDbType = SqlDbType.VarChar, Size = 200, Value = lastUpdatedBy });
sqlParams.Add(new SqlParameter() { ParameterName = "@ConnectionTypeDesc", SqlDbType = SqlDbType.VarChar, Size = 100, Value = connectionTypeDesc});
sqlCommand.Parameters.AddRange(sqlParams.ToArray());
return DBAccess.SQLServer.GetInteger(DBAccess.SQLServer.GetConnectionString("AccountTrackerDB"), sqlCommand);
}
My questions are:
1) What 3 things is my return statement trying to accomplish? (I believe it's attempting to get the ID, and then update the corresponding record within the database)
2)How would I write those 3 tasks into their own return statement? (I've taken one stab at it with the code that commented out) Thanks!