net连接access数据库,输出结果到页面

以前连接数据库都是SQL Server,今天忽然用到了access,开始还有点担心是不是一个样子的,后来试了一下发现和以前用SQL Server连接数据库的方式是一样的。把代码贴一下看看吧
string tableName = "music";
        OleDbConnection conn;
        OleDbDataAdapter da;
        DataTable dt 
= new DataTable();
        
string dbname = @"E:\data.mdb";// server.mappath("authors.mdb");
        conn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + dbname);
        conn.Open();
        da 
= new OleDbDataAdapter("select * from "+tableName+"", conn);
        DataSet ds 
= new DataSet();
        da.Fill(dt);
        ds.Tables.Add(dt);
        ds.DataSetName 
= "DataSetName";
        ds.Tables[
0].TableName = "UserInfor";
        
string aaa = ds.GetXml();
        
string bb = aaa.Insert(0"<?xml version='1.0' encoding='utf-8' ?>  \r\n  ");
        Response.Write(bb);
        Response.End();
我这段代码的功能是从数据库中查出满足条件的数据,然后输出到页面。但是遇到了两个问题有点想不通,所以在这里贴出来。
1、开始用的表的名称是user,每次运行的时候总是出错,说是“FROM 子句语法错误”,后来想了想发现user属于系统名称,这里的表名称定义有问题。
2、这个也是我想不通的问题,开始我没有对DataSet和DataTable定义DataSetName名称和DataTable名称,结果输出来的只是数据库中的数据,没有结构出来,后来给DataSet和DataTable随便定义个名称输出结构就对了。我这里跟踪调试了一下,发现如果没有定义名称的话,系统给个 指定的名称,分别是NewDataSet和NewDataTable。
posted on 2007-05-11 09:46  Edwin dong  阅读(684)  评论(1编辑  收藏  举报

<% Function googleColor(value, random) Dim colorArray colorArray = Split(value, ",") googleColor = colorArray(random Mod (UBound(colorArray) + 1)) End Function Function googleScreenRes() Dim screenRes, delimiter, resArray screenRes = Request.ServerVariables("HTTP_UA_PIXELS") delimiter = "x" If IsEmpty(screenRes) Then screenRes = Request.ServerVariables("HTTP_X_UP_DEVCAP_SCREENPIXELS") delimiter = "," End If resArray = Split(screenRes, delimiter, 2) If (UBound(resArray) + 1) = 2 Then googleScreenRes = "&u_w=" & resArray(0) & "&u_h=" & resArray(1) End If End Function Function googleDcmguid() Dim dcmguid dcmguid = Request.ServerVariables("HTTP_X_DCMGUID") If Not IsEmpty(dcmguid) Then googleDcmguid = "&dcmguid=" & dcmguid End If End Function Dim googleTime, googleDt, googleScheme, googleHost googleTime = DateDiff("s", "01/01/1970 00:00:00", Now()) googleDt = (1000 * googleTime) + Round(1000 * (Timer - Int(Timer))) googleScheme = "http://" If StrComp(Request.ServerVariables("HTTPS"), "on") = 0 Then googleScheme = "https://" googleHost = Server.URLEncode(googleScheme & Request.ServerVariables("HTTP_HOST")) Dim googleAdUrl, googleAdOutput googleAdUrl = "http://pagead2.googlesyndication.com/pagead/ads?" &_ "ad_type=text_image" &_ "&channel=" &_ "&client=ca-mb-pub-6539345765131754" &_ "&dt=" & googleDt &_ "&format=mobile_single" &_ "&host=" & googleHost &_ "&ip=" & Server.URLEncode(Request.ServerVariables("REMOTE_ADDR")) &_ "&markup=xhtml" &_ "&oe=utf8" &_ "&output=xhtml" &_ "&ref=" & Server.URLEncode(Request.ServerVariables("HTTP_REFERER")) &_ "&url=" & googleHost & Server.URLEncode(Request.ServerVariables("URL")) &_ "&useragent=" & Server.URLEncode(Request.ServerVariables("HTTP_USER_AGENT")) &_ googleScreenRes() &_ googleDcmguid() Set googleAdOutput = Server.CreateObject("MSXML2.ServerXMLHTTP") googleAdOutput.Open "GET", googleAdUrl, false googleAdOutput.Send Response.Write(googleAdOutput.responseText) %>