public Marchant() { Products = new List<Product>(); Products.Add(new Product("Pen", 25)); Products.Add(new Product("Pencil", 30)); Products.Add(new Product("Notebook", 15)); }
public DataTable databasecall(string username) { var con = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString(); SqlConnection mycon = new SqlConnection(con); try { DataTable dt = new DataTable(); SqlCommand cmd = new SqlCommand("Select * from Demo where NAME=@NAME", mycon); cmd.Parameters.AddWithValue("@NAME", username); mycon.Open(); SqlDataReader DR1 = cmd.ExecuteReader(); { if (DR1.HasRows) dt.Load(DR1); } //converting it to list List<DataRow> list = new List<DataRow>(); foreach (DataRow dr in dt.Rows) { list.Add(dr); } //converting it to list return dt; } catch (Exception e) { // cmd.ExecuteScalar(); mycon.Close(); return null; } }
public static string sqlstringtext() { string appPath = HttpRuntime.AppDomainAppPath + @"\sql.txt"; //string appPath = @"c:\Users\" + Environment.UserName + @"\Desktop\sql.txt"; List<string> lines = new List<string>(); using (StreamReader r = new StreamReader(appPath, Encoding.Default)) { string line; while ((line = r.ReadLine()) != null) { lines.Add(line); } } string sqltext = ""; foreach (string s in lines) { //string[] words = s; sqltext = s.Trim(); //words[0] = ""; //words[1] = ""; } return sqltext; }
protected void Button1_Click(object sender, EventArgs e) { int sheet_number = Convert.ToInt32(TextBox1.Text); int column_number = Convert.ToInt32(TextBox2.Text); string cell_entry = ""; List<string> list_images = new List<string>(); foreach (Row row in (((Workbook.Worksheets(excel_path)).ElementAtOrDefault(sheet_number-1)).Rows)) { if (row.Cells.ElementAtOrDefault(column_number-1) != null) { cell_entry = (row.Cells.ElementAtOrDefault(column_number-1)).Text; list_images.Add(cell_entry); } } List<string> distinct_images = list_images.Distinct().ToList(); foreach (var images in distinct_images) { System.Drawing.Image image = DownloadImageFromUrl("https://media.loylty.com/Gallery/" + images + ".jpg"); if (image != null) { string rootPath = ConfigurationManager.AppSettings["FolderPath1"]; string fileName1 = Server.MapPath(rootPath + images + ".jpg"); image.Save(fileName1); } } }
private string GetSeriesString() { List<Expense> expenses = Expense.GetAmountRandomAmountList(); List<string> expensesLinePoints = new List<string>(); StringBuilder seriesString = new StringBuilder(); foreach (Expense expenseItem in expenses) { expensesLinePoints.Add(expenseItem.Amount.ToString()); if (expenseItem.Date.Month == 12) { if (seriesString.Length > 0) { seriesString.Append(","); } seriesString.Append("{ "); seriesString.AppendFormat(@"name: {0}, data: [{1}]", expenseItem.Date.Year, string.Join(",", expensesLinePoints.ToArray())); seriesString.Append(" }"); expensesLinePoints = new List<string>(); } } return seriesString.ToString(); }
public void ProcessRequest(HttpContext context) { var userno = context.Request["userno"]; DateTime myDate = DateTime.Now; string myDateString = myDate.ToString("yyyy-MM-dd HH:mm:ss"); String time_start = DateTime.UtcNow.AddDays(-365).ToString("yyyy-MM-dd hh:mm:ss"); Console.WriteLine(myDateString, time_start); List<item_reminder> items = new List<item_reminder>(); using (var sql_conn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.AppSettings["ConnectionStr"])) { sql_conn.Open(); using (var sql_cmd = sql_conn.CreateCommand()) { var comm = string.Format("SELECT [pro_userno],[descr],[CreateDate] FROM HP_reminder WHERE userno = '{0}' and (CreateDate BETWEEN '{1}' AND '{2}') ORDER BY CreateDate DESC ", userno, time_start, myDateString); sql_cmd.CommandText = comm; sql_cmd.ExecuteNonQuery(); SqlDataReader sqlite_datareader1 = sql_cmd.ExecuteReader(); while (sqlite_datareader1.Read()) { items.Add(new item_reminder() { pro_userno = sqlite_datareader1["pro_userno"].ToString(), descr = sqlite_datareader1["descr"].ToString(), CreateDate = DateTime.Parse(sqlite_datareader1["CreateDate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss") }); } String data = JsonConvert.SerializeObject(items); context.Response.Clear(); context.Response.ContentType = "application/json ; charset =utf-8"; context.Response.Write(data); context.Response.End(); } } }
public void ProcessRequest(HttpContext context) { String today = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); List<item_public> items = new List<item_public>(); using (var sql_conn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.AppSettings["ConnectionStr"])) { sql_conn.Open(); using (var sql_cmd = sql_conn.CreateCommand()) { var comm = string.Format("SELECT acttitle, actbdate,actedate, content , name ,telephone ,cellphone FROM hactivity where bucd ='wkhm' and actedate >='{0}' ORDER BY actedate DESC ", today); sql_cmd.CommandText = comm; sql_cmd.ExecuteNonQuery(); SqlDataReader sqlite_datareader1 = sql_cmd.ExecuteReader(); while (sqlite_datareader1.Read()) { items.Add(new item_public() { acttitle = sqlite_datareader1["acttitle"].ToString(), actbdate = DateTime.Parse(sqlite_datareader1["actbdate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"), actedate = DateTime.Parse(sqlite_datareader1["actedate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"), content = sqlite_datareader1["content"].ToString(), name = sqlite_datareader1["name"].ToString(), telephone = sqlite_datareader1["telephone"].ToString(), cellphone = sqlite_datareader1["cellphone"].ToString() }); } String data = JsonConvert.SerializeObject(items); context.Response.Clear(); context.Response.ContentType = "application/json ; charset =utf-8"; context.Response.Write(data); context.Response.End(); } } }
protected void LinkButton1_Click(object sender, EventArgs e) { char[] trimmer={' '}; List<string> keywords = TextBox2.Text.Split(',').ToList(); List<string> filteredKeywords = new List<string>(); foreach (string word in keywords) { string temp = word.ToLower(); temp = temp.TrimEnd(trimmer); temp = temp.TrimStart(trimmer); filteredKeywords.Add(temp); } float CSMatch = Comparator.matchSpringerCS(filteredKeywords.ToArray()); float ENMatch = Comparator.matchSpringerEngineering(filteredKeywords.ToArray()); float MAMatch = Comparator.matchSpringerMA(filteredKeywords.ToArray()); SCS.Text = " Computer Science: " +CSMatch + "%"; SEN.Text = " Engineering: " + ENMatch + "%"; SMA.Text = " Mathematics: " + MAMatch + "%"; ; ; }
// checks whether student satisfies prereqs for given CourseNumber // string => bool protected bool checkClassPrereqs(string CourseNumber) { List<string> PrereqSetIDs = new List<string>(); SqlDataReader rdr; //gets PrereqSetIDs for CourseNumber from server, puts them in PrereqSetIDs string sql = "SELECT PrereqSetID FROM wi.tbl_prereq_set WHERE CourseNumber = @CourseNumber;"; MyConnection.Open(); SqlCommand cmd = new SqlCommand(sql, MyConnection); cmd.Parameters.Add("@CourseNumber", System.Data.SqlDbType.VarChar); cmd.Parameters["@CourseNumber"].Value = CourseNumber; rdr = cmd.ExecuteReader(); while (rdr.Read()) { //PrereqSetIDs.Add(rdr.GetString(0)); PrereqSetIDs.Add(rdr.GetValue(0).ToString()); } if (cmd != null) cmd.Dispose(); if (MyConnection != null) MyConnection.Close(); if (rdr != null) rdr.Dispose(); MyConnection.Close(); //for each PrereqSetID, gets its classes from server and checks whether studenthistory contains them foreach (string PrereqSetID in PrereqSetIDs) { List<string> PrereqSet = new List<string>(); bool setRet = false; sql = "SELECT Prereq FROM wi.tbl_prereq WHERE PrereqSetID = @PrereqSetID;"; MyConnection.Open(); cmd = new SqlCommand(sql, MyConnection); cmd.Parameters.Add("@PrereqSetID", System.Data.SqlDbType.VarChar); cmd.Parameters["@PrereqSetID"].Value = PrereqSetID; rdr = cmd.ExecuteReader(); while (rdr.Read()) { //checks if returned classes are in StudentHistory if (studentHistory.Contains(rdr.GetString(0))) setRet = true; } if (cmd != null) cmd.Dispose(); if (MyConnection != null) MyConnection.Close(); if (rdr != null) rdr.Dispose(); MyConnection.Close(); //returns false if the PrereqSet isn't satisfied if (!setRet) return false; } if (cmd != null) cmd.Dispose(); if (MyConnection != null) MyConnection.Close(); if (rdr != null) rdr.Dispose(); MyConnection.Close(); //returns true if no prereqs are missing for the PrereqSets return true; }
public static List<Customers> PopulateDropDownList() { DataTable dt = new DataTable(); List<Customers> objDept = new List<Customers>(); using (SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=ylena_exercise;Integrated Security=True")) { using (SqlCommand cmd = new SqlCommand("SELECT CustomerId, CustomerName, ContactName, Address, City, PostalCode, Country FROM Customers", con)) { con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { objDept.Add(new Customers { CustomerId = dt.Rows[i]["CustomerId"].ToString(), CustomerName = dt.Rows[i]["CustomerName"].ToString(), ContactName = dt.Rows[i]["ContactName"].ToString(), Address = dt.Rows[i]["Address"].ToString(), City = dt.Rows[i]["City"].ToString(), PostalCode = dt.Rows[i]["PostalCode"].ToString(), Country = dt.Rows[i]["Country"].ToString() }); } } return objDept; } } }
protected void Page_Load(object sender, EventArgs e) { var myLog = new List<string>(); myLog.Add(string.Format("{0} - Logging Started", DateTime.UtcNow)); logListView.DataSource = myLog; logListView.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { List<MyRecord> myRecordList = new List<MyRecord>(); myRecordList.Add(new MyRecord() { Id = 1, Name = "John" }); myRecordList.Add(new MyRecord() { Id = 2, Name = "Sue" }); myRecordList.Add(new MyRecord() { Id = 3, Name = "Jack" }); DropDownList1.DataSource = myRecordList; DropDownList1.DataTextField = "Name"; DropDownList1.DataValueField = "Id"; DropDownList1.DataBind(); using (SqlConnection cn = new SqlConnection()) { } }
public static List<string> acm(string uri) { List<string> acmkeywords = new List<string>(); int counter = 0; string ccsforthisarticle = "CCS for this Article"; string end = "]);"; bool printNow = false; string quoteandgreatersymbol = "\">"; string path = HttpContext.Current.Server.MapPath("~/App_Data/ACMhtmlFile.txt"); Stream writer = new FileStream(path, FileMode.Create); writer.Close(); // string link = "http://dl.acm.org/citation.cfm?id=1073209&CFID=574953640&CFTOKEN=74149999"; using (WebClient client = new WebClient()) { client.DownloadFile(uri, path); foreach (var line in File.ReadLines(path)) { if (printNow) { if (line.Contains(end)) { printNow = false; counter++; } } if (printNow) { if (line.Contains(quoteandgreatersymbol)) { var a = line.IndexOf("href"); var b = line.LastIndexOf("/a>"); var c = line.Substring(a, b - a); var d = c.IndexOf('>'); var e = c.IndexOf('<'); var f = c.Substring(d, e - d); acmkeywords.Add(f.Trim('>')); System.Diagnostics.Debug.WriteLine(f.Trim('>')); } } if ((line.Contains(ccsforthisarticle)) && counter == 0) printNow = true; } } return acmkeywords; }
public void ProcessRequest(HttpContext context) { var userid = context.Request["userid"]; String data = ""; List<item_check> items = new List<item_check>(); using (var sql_conn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.AppSettings["ConnectionStr"])) { sql_conn.Open(); using (var sql_cmd = sql_conn.CreateCommand()) { var comm = string.Format("SELECT userid FROM employees where userid = '{0}' ", userid); sql_cmd.CommandText = comm; sql_cmd.ExecuteNonQuery(); SqlDataReader sqlite_datareader1 = sql_cmd.ExecuteReader(); while (sqlite_datareader1.Read()) { items.Add(new item_check() { userid = sqlite_datareader1["userid"].ToString(), }); } data = JsonConvert.SerializeObject(items); if (data == "[]") { context.Response.Clear(); context.Response.ContentType = "application/json ; charset =utf-8"; context.Response.Write("YES"); context.Response.End(); } else { context.Response.Clear(); context.Response.ContentType = "application/json ; charset =utf-8"; context.Response.Write("NO"); context.Response.End(); } context.Response.Clear(); context.Response.ContentType = "application/json ; charset =utf-8"; context.Response.Write(data); context.Response.End(); } } }
/// <summary> /// 匹配页面的图片地址 /// </summary> /// <param name="HtmlCode"></param> /// <param name="imgHttp">要补充的http://路径信息</param> /// <returns></returns> public List<string> GetImgSrc(string HtmlCode) { List<string> list = new List<string>(); string Reg = @""; Reg = "(?is)<img.*?src=(['\"]?)(?<url>[^'\" ]+)(?=\\1)[^>]*>"; foreach (Match m in Regex.Matches(HtmlCode, Reg, RegexOptions.IgnoreCase)) { list.Add(m.Groups["url"].Value); } return list; }
private void BindData() { var items = new List<int>(); for (int i = 0; i < 100; i++) { items.Add(i + 1); } gridView1.DataSource = items; gridView1.DataBind(); }
public static void SetWords() { words= new List<string>(); string[] splitter = { ",","\n","\r" }; int i = 0; string[] kwords = new string[140]; Journal[] j=DataManager.GetJournalData(); foreach(Journal journal in j) { kwords[i] = journal.Keywords; i++; } foreach(string tword in kwords) { string[] tempKeywords = tword.Split(splitter, StringSplitOptions.RemoveEmptyEntries); foreach (string keyword in tempKeywords) { string temp = keyword; temp = temp.TrimEnd(); temp = temp.TrimStart(); temp = temp.Replace("(", " "); temp = temp.Replace(")", " "); temp = temp.Replace("'", ""); temp = temp.Replace("\n", ""); temp = temp.Replace("\r", ""); temp = temp.Replace("\\", ""); temp = temp.Replace("/", ","); temp = temp.Replace(" ", "-"); temp = temp.ToLower(); if (words.Contains(temp)) { } else { words.Add(temp); } } } }
public List<string> BuildList(string startDate, string open, string high, string low, string close, string volume, string adjClose) { List<string> result = new List<string>(); result.Add(startDate); result.Add(open); result.Add(high); result.Add(low); result.Add(close); result.Add(volume); result.Add(adjClose); return result; }
protected void Page_Load(object sender, EventArgs e) { DataList1.DataSource = new int[] { 1,2 }; DataList1.DataBind(); List<obj> list = new List<obj>(); for (int i = 0; i < 3; i++) { obj tmp = new obj(); tmp.IDs = i.ToString(); list.Add(tmp); } dgDataList.DataSource = list; dgDataList.DataBind(); }
public void ProcessRequest(HttpContext context) { DateTime myDate = DateTime.Now; string myDateString = myDate.ToString("yyyy-MM-dd HH:mm:ss"); String time_start = DateTime.UtcNow.AddDays(-365).ToString("yyyy-MM-dd hh:mm:ss"); Console.WriteLine(myDateString, time_start); String data = ""; List<item_knowledge> items = new List<item_knowledge>(); using (var sql_conn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.AppSettings["ConnectionStr"])) { sql_conn.Open(); using (var sql_cmd = sql_conn.CreateCommand()) { var comm = string.Format("SELECT [title] ,[content] ,[type],[update_date] ,[klg_tel] ,[klg_fax] ,[klg_addr] ,[klg_mail],[klg_mail],url FROM HP_Knowledge WHERE bucd='wkhm' and (update_date BETWEEN '{0}' AND '{1}') and type<=6 ORDER BY update_date DESC ", time_start, myDateString); sql_cmd.CommandText = comm; sql_cmd.ExecuteNonQuery(); SqlDataReader sqlite_datareader1 = sql_cmd.ExecuteReader(); while (sqlite_datareader1.Read()) { items.Add(new item_knowledge() { title = sqlite_datareader1["title"].ToString(), // content = Regex.Replace(delete(sqlite_datareader1["content"].ToString()),@"[^\w\.@-]",""), content =sqlite_datareader1["content"].ToString(), type = sqlite_datareader1["type"].ToString(), update_date = sqlite_datareader1["update_date"].ToString(), klg_tel = sqlite_datareader1["klg_tel"].ToString(), klg_fax = sqlite_datareader1["klg_fax"].ToString(), klg_addr = sqlite_datareader1["klg_addr"].ToString(), klg_mail = sqlite_datareader1["klg_mail"].ToString(), url = sqlite_datareader1["url"].ToString() }); } data = JsonConvert.SerializeObject(items); context.Response.Clear(); context.Response.ContentType = "application/json ; charset =utf-8"; context.Response.Write(data); context.Response.End(); } } }
private static List<Route> ReadFromXml() { XDocument doc = XDocument.Load("D:\\routes.xml"); XElement xml_list = doc.Root; List<Route> ListOfAllComposition = new List<Route>(); foreach(XElement xml_route in xml_list.Elements()) { Route newRoute = new Route(); newRoute.NumberOfBus=xml_route.Element("NumberOfBus").Value; foreach(XElement xml_st in xml_route.Element("Stations").Elements()) newRoute.Stations.Add(xml_st.Value.ToString()); ListOfAllComposition.Add(newRoute); } return ListOfAllComposition; }
public void ProcessRequest(HttpContext context) { var userid = context.Request["userid"]; double usertime =double.Parse(context.Request["usertime"]); DateTime dt = DateTime.Now; String format = "yyyy-MM-dd hh:mm:ss.zzz"; String str = dt.ToString(format); String today = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); String renge = DateTime.Now.AddDays(usertime).ToString("yyyy-MM-dd hh:mm:ss"); String data = ""; List<item> items = new List<item>(); using (var sql_conn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.AppSettings["ConnectionStr"])) { sql_conn.Open(); using (var sql_cmd = sql_conn.CreateCommand()) { var comm = string.Format("SELECT rowid, userno, datadate, keeptime, bhp, blp, pulse FROM measemp WHERE userno = '{0}' and (datadate BETWEEN '{1}' AND '{2}') and measure_id='M01' ORDER BY datadate asc ", userid, renge, today); sql_cmd.CommandText = comm; sql_cmd.ExecuteNonQuery(); SqlDataReader sqlite_datareader1 = sql_cmd.ExecuteReader(); while (sqlite_datareader1.Read()) { items.Add(new item() { rowid = sqlite_datareader1["rowid"].ToString(), userno = sqlite_datareader1["userno"].ToString(), datadate = DateTime.Parse(sqlite_datareader1["datadate"].ToString()).ToString("yyyy-MM-dd hh:mm:ss"), keeptime = sqlite_datareader1["keeptime"].ToString(), bhp = sqlite_datareader1["bhp"].ToString(), blp = sqlite_datareader1["blp"].ToString(), pulse = sqlite_datareader1["pulse"].ToString() }); } data = JsonConvert.SerializeObject(items); context.Response.Clear(); context.Response.ContentType = "application/json ; charset =utf-8"; context.Response.Write(data); context.Response.End(); } } }
public static void ReadBooking(List<teetime> booked, DateTime date) { string filePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "//bookings.txt"; using (System.IO.FileStream bookingStream = new System.IO.FileStream(filePath, FileMode.Open, FileAccess.Read)) { using (StreamReader reader = new StreamReader(bookingStream)) { String line; while ((line = reader.ReadLine()) != null) { string[] read = line.Split('\t'); teetime booking = new teetime() { time = Convert.ToDateTime(read[0]), booker = new customer() { firstName = (read[1]), lastName = (read[2]), email = (read[3]) }, numGuests = int.Parse(read[4]) }; booked.Add(booking); } } } }
public IEnumerable<Tool> GetTools() { List<Tool> allTools = new List<Tool>(); using (IDbConnection sqlConnection = new SqlConnection()) { sqlConnection.Open(); var tools = sqlConnection.Query("select * from Tools", null, null, true, null, CommandType.Text); foreach(var t in tools) { allTools.Add(t as Tool); } sqlConnection.Close(); } return allTools; }
public static List<Info> TakeInfoFromTheBase() { var listOfDate = new List<Info>(); using (var reader = new StreamReader(Operation.FilePath)) { var currentDateLine = reader.ReadLine(); while (currentDateLine != null) { var currentDate = currentDateLine.Split('|'); var date = new Info( DateTime.Parse(currentDate[0].Trim()), currentDate[1].Trim(), double.Parse(currentDate[2].Trim())); listOfDate.Add(date); currentDateLine = reader.ReadLine(); } } return listOfDate; }
public static List<string> GetData(string tableName) { SQLCon = new SqlCeConnection(); string ConString = @"Data Source=|DataDirectory|KeywordsDB.sdf;"; //@"Data Source=" + "F:\\Github\\JournalClassifier\\WebApplication1\\WebApplication1\\App_Data\\KeywordsDB.sdf;"; SQLCon.ConnectionString = ConString; List<string> WordList = new List<string>(); SQLCon.Open(); string Comm = "SELECT * FROM "+tableName; SQLAdp = new SqlCeDataAdapter(Comm, SQLCon); SQLAdp.SelectCommand = new SqlCeCommand(Comm, SQLCon); SQLdset = new DataSet(); SQLAdp.Fill(SQLdset,tableName); SQLCon.Close(); if (SQLdset != null) { ; int j = SQLdset.Tables[tableName].Rows.Count; ; for (int i = 0; i < j ; i++) { string temp = SQLdset.Tables[tableName].Rows[i]["Keywords"].ToString(); WordList.Add(temp.ToLower()); } } return WordList; }
//sinnloser Kommentar um git zu testen void Application_Start(object sender, EventArgs e) { // Code, der beim Starten der Anwendung ausgeführt wird. List<Chatter> chatters = new List<Chatter>(); /*chatters.Add(new Chatter(new Guid("CD863C27-2CEE-45fd-A2E0-A69E62B816B9"), "Me")); chatters.Add(new Chatter(Guid.NewGuid(), "Juan")); chatters.Add(new Chatter(Guid.NewGuid(), "Joe")); chatters.Add(new Chatter(Guid.NewGuid(), "Eric")); chatters.Add(new Chatter(Guid.NewGuid(), "Brian")); chatters.Add(new Chatter(Guid.NewGuid(), "Kim")); chatters.Add(new Chatter(Guid.NewGuid(), "Victor"));*/ Application.Add("Chatters", chatters); List<Chat> chats = new List<Chat>(); chats.Add(new Chat()); Application.Add("Chats", chats); /* foreach (KeyValuePair<Guid, Chatter> chatter in Chatter.ActiveChatters()) { chatter.Value.Join(Chat.ActiveChats()[0]); }*/ }
protected void Page_Load(object sender, EventArgs e) { string cs = ConfigurationManager.ConnectionStrings["appConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(cs); SqlCommand sql = new SqlCommand("SELECT * FROM SalesLT.Customer", con); List<CustomerClass> customers = new List<CustomerClass>(); con.Open(); SqlDataReader reader = sql.ExecuteReader(); while (reader.Read()) { CustomerClass customer = new CustomerClass(); customer.CustomerID = Convert.ToInt32(reader["CustomerID"]); customer.FullName = reader["FirstName"].ToString() + " " + reader["LastName"].ToString(); customer.Phone = reader["Phone"].ToString(); customers.Add(customer); } con.Close(); GridView1.DataSource = customers; GridView1.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { List<Produit> uneListeDeProduits = new List<Produit>(); MySqlConnection cnx = new MySqlConnection("server=localhost;user=root;password=root;database=magasin"); cnx.Open(); MySqlCommand cmd = cnx.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM produit ORDER BY id"; using (DbDataReader dbrdr = cmd.ExecuteReader()) { while (dbrdr.Read()) { int id = 0; int.TryParse(dbrdr["id"].ToString(), out id); double prixUnitaire = 0; String designation = dbrdr["designation"].ToString(); Double.TryParse(dbrdr["prixUnitaire"].ToString(), out prixUnitaire); int quantiteEnStock = 0; int.TryParse(dbrdr["quantiteEnStock"].ToString(), out quantiteEnStock); uneListeDeProduits.Add(new Produit(id, designation, prixUnitaire, quantiteEnStock)); } LiteralControl chaineHtml = new LiteralControl(); chaineHtml.Text = "<table border=\"1px solid black\""; for (int i = 0; i < uneListeDeProduits.Count; i++) { chaineHtml.Text += "<tr>"; chaineHtml.Text += "<td>" + uneListeDeProduits[i].Id + "</td>"; chaineHtml.Text += "<td>" + uneListeDeProduits[i].Designation + "</td>"; chaineHtml.Text += "<td>" + uneListeDeProduits[i].PrixUnitaire + " $</td>"; chaineHtml.Text += "<td>" + uneListeDeProduits[i].QuantiteEnStock + " $</td>"; chaineHtml.Text += "</tr>"; } localPlaceHolder.Controls.Add(chaineHtml); } cnx.Close(); }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack == false) { List<Matricula> lstMatriculas = new List<Matricula>(); lstMatriculas.Add(new Matricula() { Codigo = 11, NombreEstud = "Hamilton Mesa", Valor = 5000 }); lstMatriculas.Add(new Matricula() { Codigo = 22, NombreEstud = "Ferney", Valor = 6000 }); lstMatriculas.Add(new Matricula() { Codigo = 38, NombreEstud = "Luis", Valor = 7000 }); lstMatriculas.Add(new Matricula() { Codigo = 44, NombreEstud = "Carlos", Valor = 8000 }); lstMatriculas.Add(new Matricula() { Codigo = 55, NombreEstud = "Erwin", Valor = 9000 }); lstMatriculas.Add(new Matricula() { Codigo = 17, NombreEstud = "Jesus", Valor = 1000 }); Session["Matri"] = lstMatriculas; GridMatricula.DataSource = lstMatriculas; GridMatricula.DataKeyNames = new string[] { "Codigo" }; GridMatricula.DataBind(); } }