web.config配置文件链接数据库的方法
作者:网络转载 发布时间:[ 2013/10/25 11:56:14 ] 推荐标签:
【1】在web.config配置文件中,
|
<connectionStrings>
<add name="NorthwindConnectionString" connectionString="Data Source=localhost;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=sa"
providerName="System.Data.SqlClient" />
</connectionStrings>
|
【2】在后台中,引入程序集或者手工引入:using System.Web.Configuration;
【3】后台写入的方法为:
|
protected void Page_Load(object sender, EventArgs e)
{
//从web.config中引用连接字符串
string strConn = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
SqlConnection myConn = new SqlConnection(strConn);
string strSQL = "SELECT Top 5 CategoryID,CategoryName,Description From Categories";
SqlCommand myCommand = new SqlCommand(strSQL, myConn);
myConn.Open();
myGv.DataSource = myCommand.ExecuteReader();
myGv.DataBind();
myConn.Close();
}
|
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系SPASVO小编(021-61079698-8054),我们将立即处理,马上删除。
相关推荐
在测试数据库性能时,需要注意哪些方面的内容?测试管理工具TC数据库报错的原因有哪些?怎么解决?数据库的三大范式以及五大约束编程常用的几种时间戳转换(java .net 数据库)优化mysql数据库的几个步骤数据库并行读取和写入之Python实现深入理解数据库(DB2)缓冲池(BufferPool)国内三大云数据库测试对比预警即预防:6大常见数据库安全漏洞数据库规划、设计与管理数据库-事务的概念SQL Server修改数据库物理文件存在位置使用PHP与SQL搭建可搜索的加密数据库用Python写一个NoSQL数据库详述 SQL 中的数据库操作详述 SQL 中的数据库操作Java面试准备:数据库MySQL性能优化

sales@spasvo.com