Beispiel #1
0
        private void btnUpload_Click(object sender, RoutedEventArgs e)
        {
            CarData d = new CarData(comboBox.SelectedValue.ToString(),
                                    Convert.ToInt32(futottkm_text.Text), Convert.ToInt32(kmallas_text.Text),
                                    Convert.ToInt32(fogyasztas_text.Text), szerviz_text.Text.ToString(),
                                    Convert.ToInt32(ar_text.Text));

            database.AddCarData(comboBox.SelectedValue.ToString(), d);
            dataGrid.DataContext = database.GetCarData(comboBox.SelectedValue.ToString());
        }
Beispiel #2
0
        public void AddCarData(string carname, CarData car)
        {
            string sql = "INSERT INTO data ([autoid], [futottkm], [kmallas], [fogyasztas], [szerviz], [ar]) VALUES ([@Autoid], [@Futottkm], [@Kmallas], [@Fogyasztas], [@Szerviz], [@Ar])";

            using (OleDbConnection cn = new OleDbConnection
                                            (@"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = 'db.mdb'"))
                using (OleDbCommand cmd = new OleDbCommand(sql, cn))
                {
                    cn.Open();
                    cmd.Parameters.AddWithValue("@Autoid", GetAutoID(carname));
                    cmd.Parameters.AddWithValue("@Futottkm", car.futottkm);
                    cmd.Parameters.AddWithValue("@Kmallas", car.kmallas);
                    cmd.Parameters.AddWithValue("@Fogyasztas", car.fogyasztas);
                    cmd.Parameters.AddWithValue("@Szerviz", car.szerviz);
                    cmd.Parameters.AddWithValue("@Ar", car.ar);
                    cmd.ExecuteNonQuery();
                    cn.Close();
                }
        }
Beispiel #3
0
        public List <CarData> GetCarDataList(string carname)
        {
            List <CarData> l = new List <CarData>();
            CarData        d;
            string         sql     = "SELECT nev, futottkm, kmallas, fogyasztas, szerviz, ar FROM data INNER JOIN cars ON data.autoid = cars.id WHERE autoid=" + GetAutoID(carname);
            OleDbCommand   command = con.CreateCommand();

            command.CommandText = sql;
            command.CommandType = CommandType.Text;

            try
            {
                con.Open();
                OleDbDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    d = new CarData(reader["nev"].ToString(), Convert.ToInt32(reader["futottkm"]), Convert.ToInt32(reader["kmallas"]), Convert.ToInt32(reader["fogyasztas"]), reader["szerviz"].ToString(), Convert.ToInt32(reader["ar"]));
                    l.Add(d);
                }
                return(l);
            }

            catch (Exception ex)
            {
                MessageBox.Show("Ellenőrizd az adatbázis kapcsolat meglétét!");
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }

            return(null);
        }