public CodeMsg Incluir(AmigosMd Amg) { CodeMsg cm = new CodeMsg(); try { string sql = "Insert into Amigos"; sql += " ( Nome, Address, Email, Phone ) values "; sql += $" ( '{@Amg.Nome}', '{@Amg.Address}', '{@Amg.Email}', '{@Amg.Phone}')"; using SqlConnection cn = new SqlConnection(CnnString); using SqlCommand cmd = new SqlCommand(sql, cn); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); cm.ErrCode = 0; cm.ErrMsg = $"Registro { Amg.Nome} gravado"; } catch (Exception) { throw; } return(cm); }
public CodeMsg Deletar(int RowId) { CodeMsg cm = new CodeMsg(); try { string sql = "Delete from Amigos where RowId = " + $"{RowId}"; using SqlConnection cn = new SqlConnection(CnnString); using SqlCommand cmd = new SqlCommand(sql, cn); { cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); cm.ErrCode = 0; cm.ErrMsg = $"Registro {RowId} excluido"; } } catch (Exception ex) { throw ex; } return(cm); }
public async Task <CodeMsg> DeletarAsync(int RowId) { CodeMsg cm = new CodeMsg(); try { string sql = "Delete from Amigos where RowId = " + $"{RowId}"; using SqlConnection cn = new SqlConnection(CnnString); using SqlCommand cmd = new SqlCommand(sql, cn); { await cn.OpenAsync(); await Task.Run(() => cmd.ExecuteNonQueryAsync()); cn.Close(); cm.ErrCode = 0; cm.ErrMsg = $"Registro {RowId} excluido"; } } catch (Exception ex) { throw ex; } return(cm); }