sqlDB类

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;

usingSystem.Data;
usingSystem.Data.SqlClient;
namespacetestdat
{
publicclasssqlDB:IDisposable
{
publicSystem.Data.SqlClient.SqlConnectionconn;
publicSystem.Data.SqlClient.SqlCommandcommand;

publicsqlDB()
{
conn=newSqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["server"].ConnectionString);
conn.Open();
command=conn.CreateCommand();
}

publicDataTableReadTable()
{
SqlDataAdapteradapter=newSqlDataAdapter(command);
DataTabledt=newDataTable();
adapter.Fill(dt);
returndt;
}


publicvoidDispose()
{
conn.Close();
}
}
}

配置:

<connectionStrings>
<addname="ApplicationServices"
connectionString="datasource=.\SQLEXPRESS;IntegratedSecurity=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;UserInstance=true"
providerName="System.Data.SqlClient"/>
<addname="server"connectionString="server=.;database=test;IntegratedSecurity=True;"providerName="System.Data.SqlClient"/>

<addname="connection"connectionString="server=110.249.157.35;database=wodegw;uid=sa;pwd=sa;"providerName="System.Data.SqlClient"/></connectionStrings>

你可能感兴趣的:(.net,配置,sqlDB类)