public int?Set_Servico(SERVICO_DTO DTO) { using (SqlConnection cn = new SqlConnection(strConnection)) { try { SqlDataReader dr = null; StringBuilder SQL_ = new StringBuilder(); SQL_.Append("INSERT INTO "); SQL_.Append("SERVICOS "); SQL_.Append("( "); SQL_.Append("NOME, "); SQL_.Append("VALOR "); SQL_.Append(") "); SQL_.Append("VALUES "); SQL_.Append("( "); SQL_.Append("@NOME, "); SQL_.Append("@VALOR "); SQL_.Append("); SELECT SCOPE_IDENTITY(); "); cn.Open(); SqlCommand cmd = new SqlCommand(SQL_.ToString(), cn); cmd.Parameters.AddWithValue("@NOME", DTO.NOME); cmd.Parameters.AddWithValue("@VALOR", DTO.VALOR); if ((DTO.ID = Convert.ToInt32(cmd.ExecuteScalar())) > 0) { return(DTO.ID); } return(0); } catch (SqlException ex) { throw new Exception(ex.ToString()); } catch (Exception ex) { throw new Exception(ex.ToString()); } finally { cn.Close(); } } }
public int?Set_Servico(SERVICO_DTO DTO) { return(DAO.Set_Servico(DTO)); }