如何用vb6.0向access中写入数据?
如题 --------------------编程问答-------------------- http://blog.csdn.net/jackyuanhua/archive/2007/09/09/1778397.aspx --------------------编程问答-------------------- dim conn as new adodb.connectionIf conn.State = adStateOpen Then conn.Close
conn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Mode=ReadWrite;Persist Security Info=False"
.Open
'增加记录
conn.execute "insert into tablename(...) values(...)"
'修改记录
conn.execute "update tablename set ... where ..."
'删除记录
conn.execute "delete from tablename where ..."
--------------------编程问答-------------------- 不过写入ACCESS时候字段的格式应该是:字符字段:'" & m_String & "' ; 日期时间:#" & m_Today & "#;而数值的字段为:" & m_Number & "
这点和MSSQL不一样 --------------------编程问答-------------------- 如果按二楼的写法,查询是不是应该这样写?
--------------------编程问答-------------------- 楼上的,SELECT要求的是返回,你那样写是执行了,但是你怎么得到返回的数据呢?
conn.execute "select 字段 from 表名 where 查询条件"
我的方法如下
data.bas
Option Explicit
Public cn As ADODB.Connection
Public rs As ADODB.Recordset
Public Function conn() As Boolean '定义CONN
Set cn = New Connection
On Error GoTo cnerr
Dim connect As Boolean
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dates.mdb;"
cn.ConnectionTimeout = 20
cn.Open
conn = True
Exit Function
cnerr:
conn = False
MsgBox Err.Description
End Function
Public Function openrs(ByVal sqlstr As String) As Boolean '定义RS
Set rs = New Recordset
On Error GoTo rserr
rs.Open sqlstr, cn, adOpenDynamic, adLockOptimistic, -1
openrs = True
Exit Function
rserr:
openrs = False
MsgBox Err.Description
End Function
应用
if conn() then '查询
If openrs("select top 1 * from gs where xx_yes='no' order by gs_id") Then
If Not (rs.EOF And rs.BOF) Then
Text1.Text = CStr(rs!gs_id)
End If
end if
end if
If conn() Then ' 更新
sqls = "select * from gs "
If openrs(sqls) Then
rs.AddNew
rs!gs_id = text1.text
rs.Update
rs.Close
Set rs = Nothing
End If
end if
补充:VB , 数据库(包含打印,安装,报表)