private void StartWithMyCity() { string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\serge\source\repos\BaigiamasisDarbas_Orai_Sergej\BaigiamasisDarbas_Orai_Sergej\City.mdf;Integrated Security=True"; SqlConnection sql = new SqlConnection(connectionString); string querry = "SELECT TOP 1 * FROM CityTable order by Id DESC"; SqlCommand command = new SqlCommand(querry, sql); sql.Open(); SqlDataReader takeCity = command.ExecuteReader(); while (takeCity.Read()) { CityTable cityTable = new CityTable(); cityTable.City = takeCity["City"].ToString(); cityName = cityTable.City; } sql.Close(); try { getWeather(); getForcast(); } catch (WebException ex) { string querry1 = "DELETE FROM CityTable"; SqlCommand command1 = new SqlCommand(querry1, sql); sql.Open(); var atsakymas1 = command1.ExecuteNonQuery(); if (atsakymas1 < 0) { MessageBox.Show("Error"); } sql.Close(); MessageBox.Show("Your city is wrong, please try again"); return; } catch (Exception ex) { MessageBox.Show("Not expected exception"); } }
private void YourCityButton_Click(object sender, EventArgs e) { CityTable myCity = new CityTable(); myCity.City = CityText.Text; string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\serge\source\repos\BaigiamasisDarbas_Orai_Sergej\BaigiamasisDarbas_Orai_Sergej\City.mdf;Integrated Security=True"; SqlConnection sql = new SqlConnection(connectionString); string querry = "Insert into CityTable(City) VALUES(@City)"; SqlCommand command = new SqlCommand(querry, sql); command.Parameters.AddWithValue("@City", CityText.Text); sql.Open(); var atsakymas = command.ExecuteNonQuery(); if (atsakymas < 0) { MessageBox.Show("Error"); } sql.Close(); MessageBox.Show("Your city saved"); StartWithMyCity(); }
partial void DeleteCityTable(CityTable instance);
partial void UpdateCityTable(CityTable instance);
partial void InsertCityTable(CityTable instance);