using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; /// /// Summary description for ToodeteHaldus /// public class ToodeteHaldus { SqlConnection yhendus = new SqlConnection( ConfigurationManager.ConnectionStrings[ "yhendusTekst"]. ConnectionString); public ToodeteHaldus() { yhendus.Open(); } //~ToodeteHaldus() { // yhendus.Close(); //} private DataTable TootedAndmeTabelina(SqlDataReader lugeja){ DataTable vastus = new DataTable("toodeteandmed"); vastus.Columns.Add("nimetus", typeof(string)); vastus.Columns.Add("hind", typeof(double)); while (lugeja.Read()) { DataRow rida = vastus.NewRow(); rida["nimetus"] = lugeja.GetString(0); double h = (double)lugeja.GetDecimal(1); rida["hind"] = h; vastus.Rows.Add(rida); } lugeja.Close(); return vastus; } public DataTable ToodeteLoetelu() { SqlCommand cm = new SqlCommand ("SELECT nimetus, hind FROM Tooted_vaade", yhendus); SqlDataReader lugeja = cm.ExecuteReader(); return TootedAndmeTabelina(lugeja); } public DataTable NahtavateToodeteLoetelu() { SqlCommand cm = new SqlCommand ("SELECT nimetus, hind FROM Tooted_vaade "+ "WHERE nahtav=1", yhendus); SqlDataReader lugeja = cm.ExecuteReader(); return TootedAndmeTabelina(lugeja); } public String ProoviTervitus() { return "Tere"; } }