熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

數據控件數據綁定方法

2013-11-13 10:00:21  來源: .NET編程 

  Datalist gridviewrepeater 數據綁定方法

  

   SqlConnection con=new SqlConnection();

   conConnectionString=server=(local);database=YourDataBase;Trusted_Connection=yes;

   conOpen();

   SqlCommand com=new SqlCommand();

   comCommandText=select * from YourTable;

   comConnection=con;

   DataGridDataSource=comExecuteReader();

   //還可以使用數據閱讀器SqlDataReader(不能使用他的構造函數)代碼如下

   //SqlDataReader dr=comExecuteReader();

   //DataGridDataSource=dr;

   //當然還可以使用ADONET的核心數據集和數據適配器;

   //SqlDataAdapter ada=new SqlDataAdapter(comCommandTextcon);

   //DataSet set=new DataSet();

   //adaFill(set);

   //DataGridDataSource=set;

   //最後計算數據綁定表達式

   DataGridDataBind();

  Checkboxlistradiobuttonlist   數據綁定

  

   SqlConnection con = new SqlConnection(server=;database=db_Trade;uid=sa;pwd=;);

           conOpen();

           SqlDataAdapter sda = new SqlDataAdapter(select top * from tb_Speciality con);

           DataSet ds = new DataSet();

           sdaFill(ds);

           thisCheckBoxListDataSource = dsTables[];

           thisCheckBoxListDataTextField = speciality_name;

           thisCheckBoxListDataValueField = speciality_id;

           thisCheckBoxListDataBind();

           conClose();


From:http://tw.wingwit.com/Article/program/net/201311/12272.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.