string strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Application.StartupPath + "\\my.mdb" ;
OleDbConnection aConnection = new OleDbConnection ( strConnect ) ;
// 建立指向数据库的连接
OleDbCommand aCommand = new OleDbCommand ( "select * from Persons" ,
aConnection ) ;
// 设计所需要返回的数据集的内容
try {
aConnection.Open ( ) ;
// 打开指向数据库连接
OleDbDataReader aReader = aCommand.ExecuteReader ( ) ;
// 返回需要的数据集内容
Console.WriteLine ( "以下就是打开后的数据集的一个字段的所有内容!" ) ;
while ( aReader.Read ( ) ) {
Console.WriteLine ( aReader.GetString (0) ) ;
}
// 屏幕输出数据集的第一个字段的所有内容,如果要第二个字段把"0"改为"1"
aReader.Close ( ) ;
// 关闭数据集
aConnection.Close ( ) ;
// 关闭指向数据库的连接
Application.StartupPath + "\\my.mdb" ;
OleDbConnection aConnection = new OleDbConnection ( strConnect ) ;
// 建立指向数据库的连接
OleDbCommand aCommand = new OleDbCommand ( "select * from Persons" ,
aConnection ) ;
// 设计所需要返回的数据集的内容
try {
aConnection.Open ( ) ;
// 打开指向数据库连接
OleDbDataReader aReader = aCommand.ExecuteReader ( ) ;
// 返回需要的数据集内容
Console.WriteLine ( "以下就是打开后的数据集的一个字段的所有内容!" ) ;
while ( aReader.Read ( ) ) {
Console.WriteLine ( aReader.GetString (0) ) ;
}
// 屏幕输出数据集的第一个字段的所有内容,如果要第二个字段把"0"改为"1"
aReader.Close ( ) ;
// 关闭数据集
aConnection.Close ( ) ;
// 关闭指向数据库的连接
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script Language="c#" runat="server">
void Page_Load()
{
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
strConnection += @"Data Source=\\Northwind.mdb";
string strSQL = "SELECT * FROM Employees ";
DataSet objDataSet = new DataSet();
OleDbConnection objConnection = new OleDbConnection(strConnection);
OleDbDataAdapter objAdapter = new OleDbDataAdapter(strSQL, objConnection);
objAdapter.Fill(objDataSet, "Employees");
DataView objDataView = new DataView(objDataSet.Tables["Employees"]);
dgNameList.DataSource=objDataView;
dgNameList.DataBind();
}</script>
<html>
<body>
<h4><%=Request.QueryString["id"]%></h4> <asp:datagrid id="dgNameList" runat="server"
BackColor="#ffffff"
CellPadding=2
CellSpacing="0"
ShowFooter="true"
Font-Size="10pt"
HeaderStyle-BackColor="#eeaadd"
EnableViewState="false"
AutoGenerateColumns="false"
AllowCustomPaging="false"
>
<HeaderStyle BackColor="#00eeaa"></HeaderStyle>
<FooterStyle BackColor="#aaaadd"></FooterStyle>
<PagerStyle Mode="NumericPages" HorizontalAlign="Right"></PagerStyle>
<SelectedItemStyle BackColor="blue"></SelectedItemStyle>
<ItemStyle BackColor="#ffffee"></ItemStyle>
<AlternatingItemStyle BackColor="#6699ff"></AlternatingItemStyle>
<Columns>
<asp:HyperLinkColumn
HeaderText="Title"
DataNavigateUrlField="Title"
DataNavigateUrlFormatString="datareadasp.aspx?id={0}"
DataTextField="Title"
DataTextFormatString="{0:c}"
/>
</Columns>
</ASP:DataGrid>
</body>
</html>
using System ;
using System.Data.OleDb ;
using System.Windows.Forms ;
超级详细啊
连接字串:Provider=Microsoft.Jet.OleDb.4.0;Data Source=c:\abc.mdb