private void btnSubmit_Click_1(object sender, EventArgs e) { Database db = new Database(); if ((txtLatitude.Text == "") || (txtLongitude.Text == "") || (txtName.Text == "")) { MessageBox.Show("Feilds are missing"); } else { Station station = new Station(); station.setName(txtName.Text); station.setLatitude(Convert.ToDouble(txtLatitude.Text)); station.setLongitude(Convert.ToDouble(txtLongitude.Text)); if (db.addStation(station)) { MessageBox.Show("Station Added Successfully!"); txtLatitude.Text = ""; txtLongitude.Text = ""; txtName.Text = ""; } else { MessageBox.Show("Unable To Add Station"); } } }
void fillComboBoxes() { SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=rms;Integrated Security=True"); SqlCommand cmd = new SqlCommand(); SqlDataReader reader; cmd.CommandType = System.Data.CommandType.Text; cmd.Connection = con; cmd.CommandText = "SELECT * FROM stationTable"; try { con.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { String stationNames = reader.GetString(0); cmboSourceStation.Items.Add(stationNames); cmboDestinationStation.Items.Add(stationNames); Station station = new Station(); station.setName(reader.GetString(0)); station.setStationId(reader.GetInt32(1)); stationlist.Add(station); } con.Close(); cmd.CommandText = "SELECT MAX(order_id) FROM orderTable"; con.Open(); reader = cmd.ExecuteReader(); reader.Read(); if (reader.IsDBNull(0)) { id = 0; } else { id = reader.GetInt32(0); } txtOrderID.Text = Convert.ToString(++id); cmd.Cancel(); con.Close(); return; } catch (Exception ex) { MessageBox.Show(ex.Message); } con.Close(); }