title: The variable name '@KorisnickoIme' has already been declared. Variable names must be unique within a query batch or stored procedure
body: <p>I try to sort the data from GridView you receive error(Is Enable Sorting).Variable names must be unique within a query batch or stored procedure.
  2.Here and adapters</p>
  
  <pre><code>{
   istorijaKupovinaDataSource.SelectCommand = @"
         SELECT   k.Datum, p.Naziv AS Proizvodjac, l.Naziv AS Lek, k.Kolicina, k.Cena, ni.Naziv AS NacinIsporuke
              FROM    Kupovina k
                      INNER JOIN Lek l ON k.LekId = l.Id 
                      INNER JOIN NacinIsporuke ni ON k.NacinIsporukeID = ni.Id 
                      INNER JOIN Proizvodjac p ON l.ProizvodjacId = p.Id 
                      INNER JOIN Kupac u ON k.KupacId = u.Id
              WHERE   u.KorisnickoIme = @KorisnickoIme
              ORDER BY k.Datum";
  
          istorijaKupovinaDataSource.SelectParameters.Add("KorisnickoIme", DbType.String, User.Identity.Name);
  
  }
  public static void Kupi(long lekID, int kolicina, decimal cena, long nacinIsporukeID, string korisnickoIme)
      {
          SqlConnection con = new SqlConnection();
          try
          {
              con.ConnectionString = ConfigurationManager.ConnectionStrings["OnlineApotekaConnectionString"].ConnectionString;
              con.Open();
  
              string updateLager = @"
              UPDATE  Lager
              SET Kolicina=Kolicina-@Kolicina
              WHERE LekID=@LekID";
  
              SqlCommand cmd = new SqlCommand(updateLager, con);
              cmd.Parameters.AddWithValue("@LekID", lekID);
              cmd.Parameters.AddWithValue("@Kolicina", kolicina);
  
              cmd.ExecuteNonQuery();
  
              string insertIntoKupovina=@"
                  INSERT INTO Kupovina (KupacID, LekID, Datum, Kolicina, Cena, NacinIsporukeID) 
                  VALUES (@KupacID, @LekID, @Datum, @Kolicina, @Cena, @NacinIsporukeID)";
  
              cmd = new SqlCommand(insertIntoKupovina, con);
              cmd.Parameters.AddWithValue("@KupacID", KupacAdapter.GetID(korisnickoIme));
              cmd.Parameters.AddWithValue("@LekID", lekID);
              cmd.Parameters.AddWithValue("@Datum", DateTime.Now.Date);
              cmd.Parameters.AddWithValue("@Kolicina", kolicina);
              cmd.Parameters.AddWithValue("@Cena", cena);
              cmd.Parameters.AddWithValue("@NacinIsporukeID", nacinIsporukeID);
  
              cmd.ExecuteNonQuery();
  
          }
          catch (Exception ex)
          {
              throw ex;
          }
          finally
          {
              con.Close();
          }
      }
  }
  </code></pre>
  
  <p>{
          SqlConnection con = new SqlConnection();</p>
  
  <pre><code>    try
      {
          con.ConnectionString = ConfigurationManager.ConnectionStrings["OnlineApotekaConnectionString"].ConnectionString;
          con.Open();
  
          string selectQuery = @"
              SELECT ID
              FROM Kupac
              WHERE KorisnickoIme = @KorisnickoIme";
  
          SqlCommand cmd = new SqlCommand(selectQuery, con);
          cmd.Parameters.AddWithValue("@KorisnickoIme", korisnickoIme);
  
          return Convert.ToInt64(cmd.ExecuteScalar());
  
      }
      catch (Exception err)
      {
          throw err;
      }
      finally
      {
          con.Close();
      }
  }
  public List&lt;Kupac&gt; SelectAll()
  {
      List&lt;Kupac&gt; list = new List&lt;Kupac&gt;();
  
      SqlConnection con = new SqlConnection();
  
      try
      {
          con.ConnectionString = ConfigurationManager.ConnectionStrings["OnlineAotekaConnectionString"].ConnectionString;
          con.Open();
          SqlCommand cmd = new SqlCommand();
          cmd.Connection = con;
  
          string selectQuery = "SELECT * FROM Kupac";
  
          cmd.CommandText = selectQuery;
          SqlDataReader reader = cmd.ExecuteReader();
  
          while (reader.Read())
          {
              list.Add(new Kupac(reader["Jmbg"].ToString(), reader["Ime"].ToString(), reader["Prezime"].ToString(), reader["Telefon"].ToString(), reader["Adresa"].ToString(), reader["Email"].ToString(), reader["KorisnickoIme"].ToString()));
          }
          reader.Close();
          return list;
      }
      catch (Exception err)
      {
          throw err;
      }
      finally
      {
          con.Close();
      }
  }
  </code></pre>
  
  <p>}</p>