public void ExecuteReadQuery(string query) { try { using (var connection = new SqlConnection(_connectionString)) { using (var command = new SqlCommand(query, connection)) { connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Kunder kunde = new Kunder( reader["Navn"].ToString(), reader["Efternavn"].ToString(), Convert.ToInt32(reader["Telefon"]), reader["City"].ToString(), reader["Adresse"].ToString()); Kundeliste.Add(kunde); } reader.Close(); } connection.Close(); } } } catch (Exception ex) { throw ex; } }
public createClient(string _NAME, string _SURNAME, int _TELEFON, string _EMAIL, string _ADRESS, string _CITY) { this._NAME = _NAME; this._SURNAME = _SURNAME; this._TELEFON = _TELEFON; this._EMAIL = _EMAIL; this._ADRESS = _ADRESS; this._CITY = _CITY; Kunder nykunde = new Kunder(_NAME, _SURNAME, _TELEFON, _ADRESS, _CITY); try { DatabaseWrapper wr = new DatabaseWrapper("Data Source=01BIBME14RHJ;Initial Catalog=H2DatabaseRefreshed;Integrated Security=True"); wr.ExecuteQuery($"INSERT INTO dbo.vKunder (Navn,Efternavn,Telefon,Adresse,City) VALUES('{nykunde.returnNavn()}','{nykunde.returnEfter()}', '{nykunde.returnTlf()}','{nykunde.returnCity()}','{nykunde.returnAdresse()}')"); } catch (Exception c) { Console.Write(c.Message); } }