asp.net2.0中连接数据库

 

SqlConnection myConnection=new SqlCOnnection()

myConnection.ConnectionString =”Data Source=localhost;”+Initial Catalog=Pubs;Integrated Security=”SSPI”;

<configuration>

<connectionStrings>

<add name=”Pubs” connectionString=”Data Source=localhost;Initial Catalog=Pubs;Integrated Security=”SSPI”

</connectionStrings>

</configuration>

String connectionString=WebConfigurationManager.ConnectionStrings[“Pubs”].ConnectionString;

SqlCommand myCommand=new SqlCommand();

myCommand.Connection=myConnection;

myCommand.CommandText=”Selet * form authors”;

or

SqlCommand myCommand=new SqlCommand(“select *from authors”,myConnection);

你可能感兴趣的:(asp.net)