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();
留言
張貼留言
您好,我是 Lawrence,這裡是我的開發筆記的網誌,如果你對我的文章有任何疑問或者有錯誤的話,歡迎留言讓我知道。