示例#1
0
        void AdatBetoltes()
        {
            string sql  = @"
SELECT id,nev,uzlet
FROM ajandek
ORDER BY nev
";
            var    comm = this.conn.CreateCommand();

            comm.CommandText = sql;
            using (var reader = comm.ExecuteReader())
            {
                while (reader.Read())
                {
                    int    id  = reader.GetInt32("id");
                    string nev = reader.GetString("nev");
                    string uzlet;
                    try
                    {
                        uzlet = reader.GetString("uzlet");
                    }
                    catch (SqlNullValueException ex)
                    {
                        uzlet = null;
                    }
                    var ajandeklista = new AjandekLista(id, nev, uzlet);
                    listBox1.Items.Add(ajandeklista);
                }
            }
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int    id         = int.Parse(textBox3.Text);
            string nev        = textBox1.Text;
            string uzlet      = textBox2.Text;
            var    insertComm = conn.CreateCommand();

            insertComm.CommandText = @"
                            INSERT INTO ajandek (id, nev,uzlet)
                            VALUES(@id, @nev, @uzlet)
                        ";
            insertComm.Parameters.AddWithValue("@id", id);
            insertComm.Parameters.AddWithValue("@nev", nev);
            insertComm.Parameters.AddWithValue("@uzlet", uzlet);
            insertComm.ExecuteNonQuery();
            AjandekLista ajandek = new AjandekLista(id, nev, uzlet);

            listBox1.Items.Add(ajandek);
        }