public int Save(Disease aDisease) { SqlConnection connection = new SqlConnection(connectionString); string query = "INSERT INTO disease_table VALUES ('" + aDisease.Name + "', '"+aDisease.Description+"', '"+aDisease.Treatment+"') "; SqlCommand aCommand = new SqlCommand(query, connection); connection.Open(); int rowAffedted = aCommand.ExecuteNonQuery(); connection.Close(); return rowAffedted; }
protected void saveButton_Click(object sender, EventArgs e) { Disease aDisease = new Disease(); aDisease.Name = diseaseTextBox.Text; aDisease.Description = descripTextBox.Text; aDisease.Treatment = treatmentTextBox.Text; msgLabel.Text = aDiseaseManager.Save(aDisease); diseaseGridView.DataSource = aDiseaseManager.ShowDisease(); diseaseGridView.DataBind(); }
public string Save(Disease aDisease) { if (IsNameExists(aDisease.Name)) { return "Name Already Exists"; } else { if (aDiseaseGateway.Save(aDisease) > 0) { return "Saved Successfully"; } else { return "Failed"; } } }
public List<Disease> ShowDisease() { List<Disease> diseaseList = new List<Disease>(); SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT * FROM disease_table"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader aReader = command.ExecuteReader(); while(aReader.Read()) { Disease aDisease = new Disease(); aDisease.Id = (int)aReader["id"]; aDisease.Name = (string) aReader["name"]; aDisease.Description = (string)aReader["description"]; aDisease.Treatment = (string)aReader["treatment"]; diseaseList.Add(aDisease); } aReader.Close(); connection.Close(); return diseaseList; }