ASP连接SQLite数据库的基本代码
第一步:创建数据库建立表 拷贝内容到剪贴板
源代码:
<%
Dim objConnect
Set objConnect = Server.CreateObject("ADODB.Connection")
With objConnect
.ConnectionString = "DRIVER={SQLite3 ODBC Driver};Database=" & Server.MapPath("test.db3")
.Open
End With
objConnect.Execute "CREATE TABLE [TEST_TBL] ([TESTID] INTEGER PageRankIMARY KEY AUTOINCREMENT,[TESTContent] NTEXT NOT NULL);"
objConnect.Close
Set objConnect = Nothing
Response.Write "Create Database OK!"
%>第二步:添入长的文本到表中 拷贝内容到剪贴板
源代码:
<%
Dim objConnect, i, strInsert
strInsert = "This is a long TEXT!"
' 构建一个长文本
For i = 0 To 5
strInsert = strInsert & strInsert
Next
Set objConnect = Server.CreateObject("ADODB.Connection")
With objConnect
.ConnectionString = "DRIVER={SQLite3 ODBC Driver};Database=" & Server.MapPath("test.db3")
.Open
End With
objConnect.Execute "INSERT INTO [TEST_TBL](TESTContent)VALUES('" & strInsert & "');"
objConnect.Close
Set objConnect = Nothing
Response.Write "Insert Data OK!"
%>第三步:查询数据库,也根本就是那里出的错 拷贝内容到剪贴板
源代码:
<%
Dim objConnect,objRs,arrResult
Set objConnect = Server.CreateObject("ADODB.Connection")
With objConnect
.ConnectionString = "DRIVER={SQLite3 ODBC Driver};Database=" & Server.MapPath("test.db3")
.Open
End With
Set objRs=objConnect.Execute("SELECT [TESTContent] FROM TEST_TBL WHERE TESTID=1")
'
' Microsoft OLE DB Provider for ODBC Drivers (0x80040E21)
' 多步 OLE DB 操作产生错误。如果可能,请检查每个 OLE DB 状态值。没有工作被完成。
'
arrResult=objRs.GetRows()
Set objRs=Nothing
objConnect.Close
Set objConnect = Nothing
Response.Write arrResult(0, 0)%>