首页 / 网页编程 / ASP.NET / ASP.NET查询ACCESS数据库的内容并在DATAVIEW中显示出来
ASP.NET查询ACCESS数据库的内容并在DATAVIEW中显示出来2011-02-08在http://blog.csdn.net/axjuan/archive/2007/02/25/1514344.aspx 这篇文章中,就可以在DATAVIEW中显示记录了,但是如果你的字段名是英文或者你想设置一下DATAVIEW的样式,使其更美观,就不能使用这么简单的代码显示了。首先,如果要把标题显示为汉字,那么需要设置DATAVIEW的AutoGenerateColumns="false",不使用默认字段名,然后再设置asp:BoundField的HeaderText属性,来改变列标题;另外可以设置HeaderStyle中的BackColor、Font-Size、HorizontalAlign等属性,使其变得更加美观。下面给一个我自己做的例子:<%@ Page Language="VB" Debug ="true" %> <%@ Import Namespace="System.Data.OleDb" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> Dim connstr As String Dim sql As String Dim mycommand As OleDbCommand Dim myread As OleDbDataReader Dim conn As OleDbConnection Sub page_load(ByVal sender As Object, ByVal e As EventArgs) connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("rizhi.mdb") & ";User Id=;Password=;" conn = New OleDbConnection(connstr) conn.Open() sql = "select * from rizhi" mycommand = New OleDbCommand(sql, conn) myread = mycommand.ExecuteReader()