發表文章

目前顯示的是 12月, 2008的文章

SqlDataSource 撰寫在後端程式碼的運用

SqlDataSource的運用方法通常由精靈產生主要用在aspx頁面,下面的例子則是撰寫在.cs檔的用法,舉查詢為例,其它的用法大致上相同 SqlDataSource sqlDataSource1 = new SqlDataSource(); sqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); string strsql = "select d.*, c.* from ProductClass c right join( " + "select * from ProductBase a left join " + "(select ProID as bProID, IsAfresh , Photo3 from ProductInfo)b " + "on a.ProID= bProID where a.DepID=@DepID) d " + "on c.ClassID = d.ClassID order by d.ProID Desc"; sqlDataSource1.SelectCommand = strsql; sqlDataSource1.SelectParameters.Add("DepID", Session["DeptID"].ToString()); //sqlDataSource1.DataSourceMode = SqlDataSourceMode.DataSet GridView1.DataSource = sqlDataSource1; GridView1.DataKeyNames = new string[] { "ProID" };//主鍵 GridView1.DataBind(); sqlDataSource1.Dispose();

SortedList (C#陣列)

表示索引鍵/值組配對的集合,這個集合按索引鍵排序,而且可以按索引鍵和索引存取。 using System.Collections; SortedList mySortList = new SortedList(); while (myDr.Read()) { //如果索引鍵不存在 if (mySortList.ContainsKey(myDr["usr_title"]) == false) {  mySortList.Add(myDr["usr_title"], myDr["usr_title"]);  drpTitle.Items.Add(myDr["usr_title"].ToString()); } } //另一例子 SortedList mySL = new SortedList(); mySL.Add(1.3, "fox"); mySL.Add(1.4, "jumped"); mySL.Add(1.5, "over"); mySL.Add(1.2, "brown"); mySL.Add(1.1, "quick"); mySL.Add(1.0, "The"); mySL.Add(1.6, "the"); mySL.Add(1.8, "dog"); mySL.Add(1.7, "lazy"); // Gets the key and the value based on the index. int myIndex = 3; Console.WriteLine("The key at index {0} is {1}.", myIndex, mySL.GetKey(myIndex)); Console.WriteLine("The value at index {0} is {1}.", myIndex, mySL.GetByIndex(myIndex)); // Gets the list of keys ...