Asp.net--Linq文法

來源:互聯網
上載者:User

標籤:

建立Linq類.dbml結尾的檔案

 

開啟建立的項,

 

 選中需要的表,直接拖進來、

 

 

然後建一個  表單,拖進一個重複器控制項

在web表單原始碼中設計表,使用Repeater中轉存放;  代碼如下

 1 <asp:Repeater ID="Repeater1" runat="server"> 2  3         <HeaderTemplate> 4             <table> 5                 <tr><td> 6                     學號</td> 7                     <td> 8                     姓名</td> 9                 </tr>10         </HeaderTemplate>11             <ItemTemplate>12                 <tr><td><%#DataBinder.Eval(Container.DataItem,"code") %><td>13                           <td><%#DataBinder.Eval(Container.DataItem,"name") %></td>14                     </tr>15             </ItemTemplate>16          <FooterTemplate>17                 </table>18          </FooterTemplate>19         </asp:Repeater>

 

在cs檔案中調用資料庫,就可以不使用DataSource,而用Linq  文法,如下

1     protected void Page_Load(object sender, EventArgs e) 2     { 3        //Ling語句 4         //變數dc代表資料庫 5         DataClassesDataContext dc = new DataClassesDataContext(); 6         //var萬能變數,from 變數名(資料) in 資料庫中的表,查詢出來的資料 7         var query = from r in dc.student select r; 8         Repeater1.DataSource = query;//repeater1的資料來源query 9         Repeater1.DataBind();//資料繫結10     }

Asp.net--Linq文法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.