最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

ASP.NET oledb连接Access数据库的方法

来源:懂视网 责编:小采 时间:2020-11-27 22:38:40
文档

ASP.NET oledb连接Access数据库的方法

ASP.NET oledb连接Access数据库的方法:使用OleDBCommand相关操作类需要引入System.Data.OleDb命名空间。 通过连接一个带密码的access数据库 读取其中的数据并置入表格中显示,验证连接和命令使用正确性。 using System; using System.Collections.Generic; using
推荐度:
导读ASP.NET oledb连接Access数据库的方法:使用OleDBCommand相关操作类需要引入System.Data.OleDb命名空间。 通过连接一个带密码的access数据库 读取其中的数据并置入表格中显示,验证连接和命令使用正确性。 using System; using System.Collections.Generic; using

使用OleDBCommand相关操作类需要引入System.Data.OleDb命名空间。

通过连接一个带密码的access数据库 读取其中的数据并置入表格中显示,验证连接和命令使用正确性。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;

public partial class _Default : System.Web.UI.Page
{
 protected void Page_Load(object sender, EventArgs e)
 {
 //数据库连接,记录集的获取
 //注意更改路径
 String sqlconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = E:/pro/web/access_test/app_data/Northwind.mdb;Jet OLEDB:Database Password=111111";
 OleDbConnection myConnection = new OleDbConnection(sqlconn);
 myConnection.Open();
 OleDbCommand myCommand = new OleDbCommand("select * from 运货商", myConnection);
 OleDbDataReader myReader;
 myReader = myCommand.ExecuteReader();
 
 //读取记录集
 Response.Write("<table border=1 cellspacing=0 cellpadding=2>");
 Response.Write("<tr bgcolor=#DAB4B4>");
 for (int i = 0; i < myReader.FieldCount; i++)
 Response.Write("<td>" + myReader.GetName(i) + "</td>");
 Response.Write("</tr>");
 
 while (myReader.Read())
 {
 Response.Write("<tr>");
 for (int i = 0; i < myReader.FieldCount; i++)
 Response.Write("<td>" + myReader[i].ToString ()+ "</td>");
 Response.Write("</tr>");
 }
 Response.Write("</table>");

 //关闭记录集和连接
 myReader.Close();
 myConnection.Close();
 }
}

效果图如下:

完整项目文件已上传。

文档

ASP.NET oledb连接Access数据库的方法

ASP.NET oledb连接Access数据库的方法:使用OleDBCommand相关操作类需要引入System.Data.OleDb命名空间。 通过连接一个带密码的access数据库 读取其中的数据并置入表格中显示,验证连接和命令使用正确性。 using System; using System.Collections.Generic; using
推荐度:
标签: 操作 连接 方法
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top