不用sqlDataSet如何从后台数据库中读取数据

注意:要引用System.Data.SqlClient

-----------引用部份如下------------------------

uses
  System.Collections, System.ComponentModel,System.Data.SqlClient,
  System.Data, System.Drawing, System.Web, System.Web.SessionState,
  System.Web.UI, System.Web.UI.WebControls, System.Web.UI.HtmlControls,
  System.Web.Security, System.Web.UI.WebControls.WebParts, System.Configuration;

-------代码部份如下-----------------------------

procedure TDefault.Button1_Click(sender: System.Object; e: System.EventArgs);
var s:string;
    CNN:SqlConnection;
    COMM:SqlCommand;
    Query:SqlDataReader;
begin
    s:='Data Source=LocalHost"MSSQL;Initial Catalog=pubs;User ID=sa;Password=admin';//连SQL-Server的字串
    CNN:=SqlConnection.Create(s);
    CNN.Open();
    COMM:=CNN.CreateCommand();
    COMM.CommandText:='select * from employee';
    Query:=COMM.ExecuteReader;
    while Query.Read do begin
      Response.Write(Query['fname'].ToString()+'      &nbsp&nbsp'+Query['lname'].ToString()+'<br>');

    end;

end;

---------------------

DoubleCat


 

 

你可能感兴趣的:(Data)