private void button1_Click(object sender, EventArgs e) { if (tb_building_name.Text == "") { MessageBox.Show("Please enter building name!"); //MLHIDE } else if (tb_country.Text == "") { MessageBox.Show(WFA_psychometric_chart.Properties.Resources.Enter_country_name); } else if (tb_city.Text == "") { MessageBox.Show(WFA_psychometric_chart.Properties.Resources.Enter_city_name); } else if (tb_ZIP.Text == "") { MessageBox.Show(WFA_psychometric_chart.Properties.Resources.enter_ZIP_number); } else { string buildingName = tb_building_name.Text; string country = tb_country.Text; string city = tb_city.Text; string state = tb_state.Text; string street = tb_street.Text; string zip = tb_ZIP.Text; string lng = tb_longitude.Text; string lat = tb_latitude.Text; string elevation = tb_elevation.Text; //now lets update the values in database... try { //lets pull the vales offline values stored in db... // string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); //string connString =@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\nischal\documents\visual studio 2013\Projects\WFA_psychometric_chart\WFA_psychometric_chart\T3000.mdb;Persist Security Info=True"; //string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dir + @"\T3000.mdb;Persist Security Info=True"; // string connString = @"Data Source=GREENBIRD;Initial Catalog=db_psychrometric_project;Integrated Security=True"; //--changing all the database to the sqlite database... string databasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string databaseFile = databasePath + @"\db_psychrometric_project.s3db"; string connString = @"Data Source=" + databaseFile + ";Version=3;"; using (SQLiteConnection connection = new SQLiteConnection(connString)) { connection.Open(); //string sql_string = "update tbl_building_location set country=@country_value,state=@state_value,city=@city_value,street=@street_value,ZIP=@zip_value where ID = 1;"; string sql_query = "INSERT INTO tbl_building_location(country,state,city,street,zip,longitude,latitude,elevation,BuildingName) VALUES(@country_value,@state_value,@city_value,@street_value,@zip_value,@long_value,@lat_value,@elevation_value,@building_name)"; SQLiteCommand command = new SQLiteCommand(sql_query, connection); command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@country_value", country); command.Parameters.AddWithValue("@state_value", state); command.Parameters.AddWithValue("@city_value", city); command.Parameters.AddWithValue("@street_value", street); command.Parameters.AddWithValue("@zip_value", zip); command.Parameters.AddWithValue("@long_value", lng); command.Parameters.AddWithValue("@lat_value", lat); command.Parameters.AddWithValue("@elevation_value", elevation); command.Parameters.AddWithValue("@building_name", buildingName); command.ExecuteNonQuery(); //MessageBox.Show("sql string = " + sql_string); MessageBox.Show(WFA_psychometric_chart.Properties.Resources.value_inserted_successfully); btn_insert_data.Enabled = false; tb_country.Text = ""; tb_city.Text = ""; tb_state.Text = ""; tb_street.Text = ""; tb_ZIP.Text = ""; tb_latitude.Text = ""; tb_longitude.Text = ""; tb_elevation.Text = ""; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }//close of else.. //lets refresh the list.... form3.fill_combobox(); }
private void button1_Click(object sender, EventArgs e) { if (tb_country.Text == "") { MessageBox.Show("Enter country name!"); } else if (tb_city.Text == "") { MessageBox.Show("Enter city name!"); } else if (tb_ZIP.Text == "") { MessageBox.Show("enter ZIP number"); } else { string country = tb_country.Text; string city = tb_city.Text; string state = tb_state.Text; string street = tb_street.Text; string zip = tb_ZIP.Text; string lng = tb_longitude.Text; string lat = tb_latitude.Text; string elevation = tb_elevation.Text; //now lets update the values in database... try { //lets pull the vales offline values stored in db... string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); //string connString =@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\nischal\documents\visual studio 2013\Projects\WFA_psychometric_chart\WFA_psychometric_chart\T3000.mdb;Persist Security Info=True"; string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dir + @"\T3000.mdb;Persist Security Info=True"; using (OleDbConnection connection = new OleDbConnection(connString)) { connection.Open(); //string sql_string = "update tbl_building_location set country=@country_value,state=@state_value,city=@city_value,street=@street_value,ZIP=@zip_value where ID = 1;"; string sql_query = "INSERT INTO tbl_building_location(country,state,city,street,zip,longitude,latitude,elevation) VALUES(@country_value,@state_value,@city_value,@street_value,@zip_value,@long_value,@lat_value,@elevation_value)"; OleDbCommand command = new OleDbCommand(sql_query, connection); command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@country_value", country); command.Parameters.AddWithValue("@state_value", state); command.Parameters.AddWithValue("@city_value", city); command.Parameters.AddWithValue("@street_value", street); command.Parameters.AddWithValue("@zip_value", zip); command.Parameters.AddWithValue("@long_value", lng); command.Parameters.AddWithValue("@lat_value", lat); command.Parameters.AddWithValue("@elevation_value", elevation); command.ExecuteNonQuery(); //MessageBox.Show("sql string = " + sql_string); MessageBox.Show("value inserted successfully!"); btn_insert_data.Enabled = false; tb_country.Text = ""; tb_city.Text = ""; tb_state.Text = ""; tb_street.Text = ""; tb_ZIP.Text = ""; tb_latitude.Text = ""; tb_longitude.Text = ""; tb_elevation.Text = ""; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }//close of else.. //lets refresh the list.... form3.fill_combobox(); }