- SqlConnection conn = new SqlConnection();
- conn.ConnectionString = connectionString;
- SqlCommand cmd = conn.CreateCommand();
- cmd.CommandText = "SELECT * FROM Automobil WHERE Proizvodjac =@pro";
- cmd.Parameters.AddWithValue("@pro", txtProizvodjac.Text);
- SqlDataReader reader;
- List<Automobili> listaAutomobila = new List<Automobili>();
- try
- {
- conn.Open();
- reader = cmd.ExecuteReader();
- while(reader.Read())
- {
- Automobili a = new Automobili();
- a.Model = reader["model"].ToString();
- a.Cena = (int)reader["cena"];
- listaAutomobila.Add(a);
- }
- }
- catch(Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.Message);
- lblgreska.Text = ex.Message;
- }
- finally
- {
- cmd.Dispose();
- conn.Close();
- }
- lblinfo.Text = "Pronadjeno je " + listaAutomobila.Count + "automobila";
- GridView1.DataSource = listaAutomobila;
- GridView1.DataBind();
- }
- --------------------------------------------------------------------------------------------------------------------------
- protected void btnPrevedi_Click(object sender, EventArgs e)
- {
- if (ddlSmer.SelectedItem.Value == "es")
- {
- EngleskoSrpski();
- }
- if (ddlSmer.SelectedItem.Value == "se")
- {
- SrpskoEngleski();
- }
- }
- private void EngleskoSrpski()
- {
- SqlConnection conn = new SqlConnection();
- conn.ConnectionString = connectionString;
- SqlCommand cmd = conn.CreateCommand();
- cmd.CommandText = "SELECT TOP 1 Srpski, Opis FROM Prevod WHERE Engleski = @rec";
- cmd.Parameters.AddWithValue("@rec", txtRec.Text);
- txtPrevod.Text = "";
- txtOpis.Text = "";
- lblInfo.Text = "";
- try
- {
- conn.Open();
- SqlDataReader reader = cmd.ExecuteReader();
- if (reader.Read())
- {
- txtPrevod.Text = reader["Srpski"].ToString();
- txtOpis.Text = reader["Opis"].ToString();
- }
- else
- {
- lblInfo.Text = "Tražena reč ne postoji u bazi!";
- }
- reader.Close();
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.Message);
- lblInfo.Text = "Greška u čitanju baze: " + ex.Message;
- }
- finally
- {
- cmd.Dispose();
- conn.Close();
- }
- }
- -----------------------------------------------------------------------------------------------------------
- if (Page.IsValid)
- {
- SqlConnection conn = new SqlConnection();
- conn.ConnectionString = connectionString;
- SqlCommand cmd = conn.CreateCommand();
- cmd.CommandText = "INSERT INTO utisak (Ime, Email, Komentar, Datum) VALUES (@ime, @email, @komentar, @datum) ";
- cmd.Parameters.AddWithValue("@ime", txtIme.Text);
- cmd.Parameters.AddWithValue("@email", txtEmail.Text);
- cmd.Parameters.AddWithValue("@komentar", txtKomentar.Text);
- cmd.Parameters.AddWithValue("@datum", DateTime.Now);
- lblInfo.Text = "";
- try
- {
- conn.Open();
- cmd.ExecuteNonQuery();
- lblInfo.Text = "Podaci su uspesno uneti";
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.Message);
- lblInfo.Text = ex.Message;
- }
- finally
- {
- conn.Close();
- cmd.Dispose();
- }