易截截图软件、单文件、免安装、纯绿色、仅160KB

ASP.NET中连接数据库的各种方法


今天,学习了ASP.NET中连接数据库的各种方法,这是我自己的一个小总结,不一定完全正确,仅供参考!   O(∩_∩)O~
 
 
连接SQL数据库的方法:
(一)、在Web.Config中创建连接字符串:
1、
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\grade.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
2、
<add name="sampleConnectionString" connectionString ="server=.\SQLEXPRESS;database=sample;uid=sa;pwd=123456;" providerName ="System.Data.SqlClient"/>
3、
<add name ="testConnectionString" connectionString ="Data Source=.\SQLEXPRESS;Initial Catalog=sample;Integrated Security=True;Persist Security Info=True;User ID=sa;Password=123456" providerName ="System.Data.SqlClient"/>
(二)、在aspx.cs中获取连接字符串:
1、
string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["sampleConnectionString"].ConnectionString;
2、
string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["sampleConnectionString"].ToString();
3、
string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["testConnectionString"].ToString();
(三)、将连接字符串直接写到页面里
1、
string strCon = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\grade.mdf;Integrated Security=True;User Instance=True";
2、
string strCon = "Data Source=.\\SQLEXPRESS;Initial Catalog=sample;Integrated Security=True;Persist Security Info=True;User ID=sa;Password=123456";
3、
string strCon = "server=.\\SQLEXPRESS;database=sample;uid=sa;pwd=123456";
连接Access数据库(yx.mdb)的方法:
(一)、在Web.Config中创建连接字符串:
<add name ="accessConnectionString" connectionString ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\yx.mdb" providerName ="System.Data.OleDb"/>
(二)、在aspx.cs中获取连接字符串:
1、
string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["accessConnectionString"].ToSt


相关文档:

ASP.NET中数据库数据导入Excel并打印

众所周知,WEB上的打印是比较困难的,常见的WEB上打印的方法大概有三种:
  1、直接利用IE的打印功能。一般来说,这种方法可以做些扩展,而不是单单的调用javascript:print()这样简单,比如,可以使用如下代码:
<OBJECT
id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</ ......

ASP.NET 2.0 二级域名Forms验证模式下共享登陆状态

在asp.net 1.1中, 二级域名Forms验证模式下共享登陆状态的方法请参考下面文章:
http://www.cnblogs.com/caomao/archive/2005/07/05/186606.html
而在asp.net 2.0中实现方法更为简单,只需修改web.config文件即可,修改方法如下:
<authentication mode="Forms">
    <forms name ......

ASP.NET2.0分页技术之使用纯sql语句的双top分页篇

Repeater在前台使用比较灵活自由,但有一个问题就是Repeater不支持直接分页,这个很多人看起来就有点不想用了,但我想大家都知道GridView控件或DataGrid控件在启用自带分页的时候其实效率是非常低的,大的不说,一但到了百万级数据以后,就会感觉是多么的痛苦和无耐了,所以即使是用DataGrid(GridView)控件,高手们还是只会 ......

asp.net实现文件下载(wap手机下载)

这个问题困扰了我两天,手机下载
 protected void Page_Load(object sender, EventArgs e)
    {
        string filename = Server.UrlDecode(Request["upload"]);
        string filePath = Server.MapPath("uploa ......

asp.net分页

1 using System;
  2 using System.Collections.Generic;
  3 using System.Collections.Specialized;
  4 using System.Linq;
  5 using System.Web;
  6 using System.Text;
  7 u ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号