private void DisplayData() { //connection SqlConnection connString = DbHandler.GetConnection(); try { connString.Open(); } catch (Exception ex) { Console.WriteLine("Exception in DBHandler", ex); } //select all data from line table string getLinecommand = "Select * From Line"; lineDataAdapter = new SqlDataAdapter(getLinecommand, connString); //select all data from line table string getStationcommand = "Select * From Station"; stationDataAdapter = new SqlDataAdapter(getStationcommand, connString); //fill the table this.stationDataAdapter.Fill( this.stationDataSet.Station); this.lineDataAdapter.Fill( this.lineDataset.Line); }
public AddLineandStation() { InitializeComponent(); //connection SqlConnection connString = DbHandler.GetConnection(); try { connString.Open(); } catch (Exception ex) { Console.WriteLine("Exception in DBHandler", ex); } string trainLine = lineTextbox.Text; DisplayData(); }
private void addLineButton_Click(object sender, EventArgs e) { string trainLine = lineTextbox.Text; //connection SqlConnection connString = DbHandler.GetConnection(); try { connString.Open(); } catch (Exception ex) { Console.WriteLine("Exception in DBHandler", ex); } // select every row in line table for name column which is the input of train line textbox string myQuery = "Select * From Line Where Name = '" + trainLine + "'"; SqlCommand myCommand = new SqlCommand(myQuery, connString); myCommand.ExecuteNonQuery(); SqlDataReader dataReader = myCommand.ExecuteReader(); //if the train line exists in the database then output a message if (dataReader.HasRows) { outputLabel.Text = "Train line already exists"; } else { try { //if not then add the data in child table DbHandler.AddLine(trainLine); outputLabel.Text = "Train line added Successfully!"; DisplayData(); ClearData(); MessageBox.Show("Successfully data added!"); } catch (Exception ex) { outputLabel.Text = "Error!" + ex; } } }