public JsonResult Create(LabelMaster label) { try { string query = @"insert into LabelMaster (Label_Name) values ('" + label.LabelName + "')"; DataTable table = new DataTable(); string sqlDataSource = configuration.GetConnectionString("DataConnection"); SqlDataReader dataReader; using (SqlConnection connection = new SqlConnection(sqlDataSource)) { connection.Open(); using (SqlCommand command = new SqlCommand(query, connection)) { dataReader = command.ExecuteReader(); table.Load(dataReader); dataReader.Close(); connection.Close(); } } return(new JsonResult("Data Inserted")); } catch { return(new JsonResult("Unauthorized user")); } }
// GET: ProductMasterController/Edit/5 public ActionResult Edit(LabelMaster label) { string query = @"Update LabelMaster set Label_Name = '" + label.LabelName + "'"; DataTable table = new DataTable(); string sqlDataSource = configuration.GetConnectionString("DataConnection"); SqlDataReader dataReader; using (SqlConnection connection = new SqlConnection(sqlDataSource)) { connection.Open(); using (SqlCommand command = new SqlCommand(query, connection)) { dataReader = command.ExecuteReader(); table.Load(dataReader); dataReader.Close(); connection.Close(); } } return(new JsonResult("Data Updated")); }