public bool AddNewAirport(AirportEntity ae) { int result; string sql = "INSERT INTO airport([code], [name], [city], [state], [country], [utc_time],[deleted], [openning]) "; sql += "VALUES(@code, @name, @city, @state, @country, @utc_time,@deleted, @openning)"; ParameterPair[] p = new ParameterPair[8]; p[0] = new ParameterPair("@code", ae.Code); p[1] = new ParameterPair("@name", ae.Name); p[2] = new ParameterPair("@city", ae.City); p[3] = new ParameterPair("@state", ae.State); p[4] = new ParameterPair("@country", ae.Country); p[5] = new ParameterPair("@utc_time", ae.UtcTime); p[6] = new ParameterPair("@deleted", ae.Deleted.ToString()); p[7] = new ParameterPair("@openning", ae.Openning.ToString()); result = _dbconnection.ExecuteNonQuery(sql, p); if (result > 0) { return(true); } else { return(false); } }
public int ExecuteNonQuery(string sql, ParameterPair[] param) { int result = 0; ConnectDB(); try { SqlCommand command = new SqlCommand(sql, _connection); SqlParameter p; for (int i = 0; i < param.Length; i++) { ParameterPair pp = param[i]; p = new SqlParameter(pp.ParameterName, pp.Value); command.Parameters.Add(p); } result = (int)command.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("ExecuteNonQuery() exception: " + ex.Message); return(0); } return(result); }
public SqlDataReader ExecuteReader(string sql, ParameterPair[] param) { ConnectDB(); SqlDataReader dr; SqlCommand command = new SqlCommand(sql, _connection); SqlParameter p; for (int i = 0; i < param.Length; i++) { ParameterPair pp = param[i]; p = new SqlParameter(pp.ParameterName, pp.Value); command.Parameters.Add(p); } dr = command.ExecuteReader(); return(dr); }
public bool DeleteAirport(string code) { int result; string sql = "DELETE FROM airport WHERE [code]=@code"; ParameterPair[] p = new ParameterPair[] { new ParameterPair("@code", code) }; result = _dbconnection.ExecuteNonQuery(sql, p); if (result > 0) { return(true); } else { return(false); } }
public DataSet GetDatasetResut(string sql, ParameterPair[] param, string tableName) { DataSet ds = new DataSet(); ConnectDB(); SqlCommand command = new SqlCommand(sql, _connection); SqlParameter p; for (int i = 0; i < param.Length; i++) { ParameterPair pp = param[i]; p = new SqlParameter(pp.ParameterName, pp.Value); command.Parameters.Add(p); } SqlDataAdapter da = new SqlDataAdapter(command); da.Fill(ds, tableName); return(ds); }