視圖應用一(First)

來源:互聯網
上載者:User

用工具產生視圖
1.建立視圖,右擊,添加表t_StoreIn,t_Goods
  有關聯欄位的,會自動關聯。
2.選擇列,sid,snum... gname
3.可以修改別名,sid為編號,gname為物品名稱。
4.在第三行,自動產生sql語句。
5.點擊執行,在第四行,輸出查詢結果。

注意,輸出查詢結果,產生的表,就是視圖當表使用時,當成的表。
改了別名,則就按改之後的名稱使用。

自動產生的程式碼
SELECT dbo.t_StoreIn.sid AS 編號, dbo.t_Goods.gname AS 物品名稱, dbo.t_StoreIn.snum,
      dbo.t_StoreIn.sdate, dbo.t_StoreIn.sprice, dbo.t_StoreIn.summary
FROM dbo.t_StoreIn INNER JOIN
      dbo.t_Goods ON dbo.t_StoreIn.gid = dbo.t_Goods.gid

 

基本操作

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. using SQLHelper;
  11. using System.Text;
  12. using System.Data.SqlClient;
  13. using System.Collections.Generic;
  14. /// <summary>
  15. /// test 的摘要說明
  16. /// </summary>
  17. public class test
  18. {
  19.     public DataTable getbyid(int 編號)
  20.     {
  21.         StringBuilder sb = new StringBuilder();
  22.         sb.Append("select * from VIEW_test where [編號]=@編號");
  23.         SqlParameter[] param = { DBHelper.GetParameter("@編號", SqlDbType.Int, 4, "[編號]", 編號) };
  24.         return DBHelper.ExecuteDt(sb.ToString(), param);
  25.     }
  26.     /// <summary>
  27.     /// 取得全部
  28.     /// </summary>
  29.     /// <returns></returns>
  30.     public DataTable getlist()
  31.     {
  32.         StringBuilder sb = new StringBuilder();
  33.         sb.Append("select * from VIEW_test");
  34.         return DBHelper.ExecuteDt(sb.ToString());
  35.     }
  36.     public test()
  37.     {
  38.         //
  39.         // TODO: 在此處添加建構函式邏輯
  40.         //
  41.     }
  42. }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.