/// <summary> /// Inserts a MarinaDBRow into the Marina table /// </summary> /// <param name="?">MarinaDBRow to be inserted</param> /// <returns>Number of rows affected in the Marina table</returns> public int Insert(MarinaDBRow row) { int returnNum = 0; String sqlQueryString = "INSERT INTO marina VALUES ('" + row.id + "','" + row.name + "','" + row.address + "','" + row.city + "','" + row.state + "','" + row.zip + "');"; SqlCommand command = new SqlCommand(sqlQueryString, dbSqlConnection); returnNum = command.ExecuteNonQuery(); return returnNum; }
/// <summary> /// Selects an individual MarinaDBRow from Marina table /// </summary> /// <param name="id">id of the requested row</param> /// <returns>MarinaDBRow object</returns> public MarinaDBRow Select(string id) { MarinaDBRow row = new MarinaDBRow(); String sqlQueryString = "SELECT marina_num, name, address, city, state, zip FROM marina WHERE marina_num = " + id + ";"; SqlCommand sqlCommand = new SqlCommand(sqlQueryString, dbSqlConnection); SqlDataReader reader = sqlCommand.ExecuteReader(); while (reader.Read()) { row.id = reader[0].ToString().Trim(); row.name = reader[1].ToString().Trim(); row.address = reader[2].ToString().Trim(); row.city = reader[3].ToString().Trim(); row.state = reader[4].ToString().Trim(); row.zip = reader[5].ToString().Trim(); } reader.Close(); return row; }
/// <summary> /// Updates a Marina row /// </summary> /// <param name="id">id value to change</param> /// <param name="row"></param> /// <returns>Number of rows updated in the Marina table</returns> public int Update(string id, MarinaDBRow row) { int numRowsAffected; String sqlQueryString = "UPDATE marina SET marina_num='" + row.id + "', name='" + row.name + "', address='" + row.address + "', city='" + row.city + "', state='" + row.state + "', zip='" + row.zip + "' WHERE marina_num='" + id + "';"; SqlCommand command = new SqlCommand(sqlQueryString, dbSqlConnection); numRowsAffected = command.ExecuteNonQuery(); return 0; }
private void btnInsert_Click(object sender, EventArgs e) { MarinaDBRow row = new MarinaDBRow(); row.id = txtNum.Text; row.name = txtName.Text; row.address = txtAddress.Text; row.city = txtCity.Text; row.state = txtState.Text; row.zip = txtZip.Text; int numRowsInserted = marina.Insert(row); MessageBox.Show(numRowsInserted + "row(s) inserted!"); }