皓翔的学习网站

-------Uml .NET RUP相关技术

 

使用ExecuteReader查询数据库

        string ConnectionString = "server=(local);database=pubs;trusted_connection=true";
        
string CommandText = "select au_lname as [Last Name], au_fname as [First Name], Address, City, State from Authors";
    
        SqlConnection myConnection 
= new SqlConnection(ConnectionString);
        SqlCommand myCommand 
= new SqlCommand(CommandText, myConnection);
    
        myConnection.Open();
    
        DataGrid1.DataSource 
= myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        DataGrid1.DataBind();

posted on 2004-07-04 11:43  Jacobhuang  阅读(2102)  评论(1)    收藏  举报

导航