.Net 连接MS SQL 数据库

string ConnectionString="workstation id="+hostname+";packet size=4096;user id="+username+";password="+password+";data source="+hostname+";persist security info=False;initial catalog="+databasename;

SqlConnection Connection 
= new System.Data.SqlClient.SqlConnection();
    
Connection.ConnectionString
=ConnectionString;

this.Connection.Open();

System.Data.SqlClient.SqlCommand SelectCommand;
 
SelectCommand= new System.Data.SqlClient.SqlCommand();
    

SelectCommand.CommandText = "select * from  "+TableName;
    

SelectCommand.Connection = this.Connection;
    

System.Data.SqlClient.SqlDataReader dr= SelectCommand.ExecuteReader();
    

posted on 2005-09-01 19:38  小鸟飞飞  阅读(875)  评论(0)    收藏  举报

导航