ASP.net中關於資料庫的內容

來源:互聯網
上載者:User
Adapter Fill Table
---------------------
const C='Data Source=LocalHost"MSSQL;Initial Catalog=pubs;User ID=sa;Password=admin';
      S='select * from employee';

procedure TmainForm.Button1_Click(sender: System.Object; e: System.EventArgs);
var Adapter:SqlDataAdapter;
    Table:DataTable;
begin
    Table:=DataTable.Create;
    Adapter:=SqlDataAdapter.Create(S,C);
    Adapter.Fill(Table);
    GridView1.DataSource:=Table;
    GridView1.DataBind;
end;
---------------------
Adapter Fill Two Table in DataSet and Show
-----------------------------------------------
const C='Data Source=LocalHost"MSSQL;Initial Catalog=pubs;User ID=sa;Password=admin';
      S='select * from employee;select * from jobs'; //Use ; to separator two  Sentence

procedure TmainForm.Button1_Click(sender: System.Object; e: System.EventArgs);
var Adapter:SqlDataAdapter;

    TableSet:DataSet;
begin

    Adapter:=SqlDataAdapter.Create(S,C);
    TableSet:= DataSet.Create;
    Adapter.Fill(TableSet);
    //---Show First Table
    GridView1.DataSource:=TableSet.Tables[0].DefaultView;
    GridView1.DataBind;
    //--Show Next Table
    GridView2.DataSource:=TableSet.Tables[1].DefaultView;
    GridView2.DataBind;
end;
--------------------------------------------------------------
GridView中如何進行資料過濾
---------------------------
const c_cnn='Data Source=LocalHost"MSSQL;Initial Catalog=Northwind;User ID=sa;Password=admin';
      c_sel='select * from customers;select * from employees;select * from suppliers';
var
   sqlDA:SqlDataAdapter;
   DS:DataSet;
procedure TDefault.Button1_Click(sender: System.Object; e: System.EventArgs);

begin
   sqlDA:=SqlDataAdapter.Create(c_sel,c_cnn);
   DS:=DataSet.Create;
   sqlDA.Fill(DS);
   GridView1.DataSource:=DS;
   GridView1.DataBind;
end;

procedure TDefault.Button2_Click(sender: System.Object; e: System.EventArgs);
begin
  DS.Tables[0].DefaultView.RowFilter:=TextBox1.Text;
  GridView1.DataSource:=DS.Tables[0].DefaultView; //注意這裡需要再次進行資料Bind
  GridView1.DataBind;
end;

-----------------------------------
如何做關係表?
-----------------
const c_cnn='Data Source=LocalHost"MSSQL;Initial Catalog=Northwind;User ID=sa;Password=admin';
      c_sel='select * from suppliers;select * from products';
var
   sqlDA:SqlDataAdapter;
   DS:DataSet;

procedure TDefault.Page_Load(sender: System.Object; e: System.EventArgs);
begin
  sqlDA:=SqlDataAdapter.Create(c_sel,c_cnn);
  DS:=DataSet.Create;
  sqlDA.Fill(DS);
end;

procedure TDefault.OnInit(e: EventArgs);
begin
  //
  // Required for Designer support
  //
  InitializeComponent;
  inherited OnInit(e);
end;

procedure TDefault.Button1_Click(sender: System.Object; e: System.EventArgs);
begin
  DS.Relations.Add('SupProd',DS.Tables[0].Columns['SupplierID'],DS.Tables[1].Columns['SupplierID']);
  //在這建立關係,關設定關係名稱
  GridView1.DataSource:=DS.Tables[0].DefaultView;
  GridView1.DataBind;
  DS.Tables[1].DefaultView.RowFilter:=DS.Tables[0].Columns['SupplierID'].ToString+'=1';
  //檢索第二張表的內容,不能做動態條件????
  GridView2.DataSource:=DS.Tables[1].DefaultView;
  GridView2.DataBind;
end;
---------如何讀取WEB.Config裡的資料庫連接配置-------------------
procedure TDefault.Button1_Click(sender: System.Object; e: System.EventArgs);
var
  configurationAppSettings: System.Configuration.AppSettingsReader;//注意這個引用
  s:string;
begin
  configurationAppSettings := System.Configuration.AppSettingsReader.Create; //必須建立佈建服務應用程式設定
  s:=(string(configurationAppSettings.GetValue('SqlConnection1.ConnectionString', TypeOf(string))));
  Response.Write(s);
end;
--------------------------------------------------------------------
關於使用frame(模板檔案)
1,Project->add->Other->ASP.netMaster Page
2,ContentPlaceHolder是保留地區,由使用者去使用,
3,其它地區是必顯區,可以把要繼的東西放在這個區間
4,project->add->new->Other-ASP.net Content Page->在Master Page File上寫上Master Page名稱
OK
------------------------------------

http://design.yesky.com/homepage/414/2215914.shtml

-------------------------------------------------
超文本不顯示底線
----------------------
<style type ="text/css">
<!-
a:link{text-decoration:none}
a:hover{text-decoration:none}
a:visited{text-decoration:none}
->
</style>
-----------------------
設超鏈色
-------------
<style>
<!--
a:link {  color: #0020FF; text-decoration: none;font-size: 9pt}
a:visited { color:#0020FF; text-decoration: none;font-size: 9pt}
a:hover {  color: red; text-decoration: none;font-size: 9pt}
-->
</style>

相關文章

聯繫我們

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