在web.config中设置数据库连接相关信息,叶面中还要再写么?帮忙大家
这是在web.config中设置数据库连接相关信息:
<connectionStrings>
<add name= "ConnectionString " connectionString= "Data Source=192.0.0.2;Initial Catalog=datacenter;Persist Security Info=True;User ID=aa;Password=bb " providerName= "System.Data.SqlClient "/>
</connectionStrings>
叶面上,有一个label
要让label.text =
select * from acct where acct_num= '90000027 ' 出来的值,请问要怎么写呢?
麻烦写的清楚一点,谢谢大家
------解决方案--------------------string connectionString = ConfigurationManager.ConnectionStrings[ "ConnectionString "].ConnectionString;//得到配置节
SqlConnection DBConnection = new SqlConnection(connectionString);//创建连接
sqlcommand cmd=new sqlcommand( "select * from acct where acct_num= '90000027 ' ",DBConnection);
using (idatareader dr=cmd.executereader())
{
while(dr.read())
{
//操作
}
}