public string Put(tblTestDepartment dep) { try { DataTable table = new DataTable(); string query = @" UPDATE tblTestDepartment SET DepartmentName = '" + dep.DepartmentName + "' WHERE DepartmentID =" + dep.DepartmentID; using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["EmployeeAppDB"].ConnectionString)) using (var cmd = new SqlCommand(query, con)) using (var da = new SqlDataAdapter(cmd)) { cmd.CommandType = CommandType.Text; da.Fill(table); } return("update Successfully"); } catch (Exception ex) { HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpStatusCode.BadRequest); httpResponseMessage.Content = new StringContent(ex.Message); throw new HttpResponseException(httpResponseMessage); //return "update failed"; } }
public string POST(tblTestDepartment dep) { try { DataTable table = new DataTable(); string query = @" insert into tblTestDepartment values ('" + dep.DepartmentName + "')"; using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["EmployeeAppDB"].ConnectionString)) using (var cmd = new SqlCommand(query, con)) using (var da = new SqlDataAdapter(cmd)) { cmd.CommandType = CommandType.Text; da.Fill(table); } return("Added Successfully"); } catch (Exception) { return("failed Add"); } }