vb6.0 无法用ADODC把SYBASE数据库里的数据存入本地ACCESS
具体步骤:ADODC1连接本地ACCESS,ADODC2连接SYBASE数据库(ODBC连接本地SYBASE正常)with adodc2.recordset
.Movefirst
DO
if i=0 then
ACCESS.EDIT
else
ACCESS.ADDNEW
end if
ACCESS.字段=SYBASE.字段 (赋值)
.update
.Movenext
Loop Until .EOF
end with
ACCESS.close
SYBASE.close
Adodc1.Refresh
Adodc2.Refresh
ACCESS.addnew 和ACCESS.EDIT 是用IF 控制的 ,找到数据就改;找不到就添加。
.update、.movenext 处报错:数据库提供程序或其它服务返回E_FAIL状态。
结果是ACCESS里并没有存入数据 --------------------编程问答-------------------- 先测试adodc2是否有数据 --------------------编程问答-------------------- ADODC2能连接到数据库,数据库里的数据都有。 --------------------编程问答-------------------- 真实代码贴出来看吧 --------------------编程问答--------------------
就是 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 贴出来了,有点长。。 --------------------编程问答-------------------- 没看到ADO数据控件属性ConnectionString的赋值句.
就看到Data1.DatabaseName = App.Path & "\" & "BROADCAST.MDB"
--------------------编程问答-------------------- ADODC1:连接ACCESS
ADODC2:连接SYBASE
是用控件的属性连的,不是代码,连接都成功的。 --------------------编程问答-------------------- data1 无视别管
--------------------编程问答-------------------- ADODC1:Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\昆山\broadcast.mdb;Persist Security Info=False --------------------编程问答-------------------- continue --------------------编程问答-------------------- sybase是用ODBC创建的数据源连的,没有代码的,不用看的。 --------------------编程问答-------------------- LZ请参考我在http://iask.sina.com.cn/b/2342798.html的代码 --------------------编程问答-------------------- 格式化一下,太长了
Dim dbBroadcast As Database--------------------编程问答-------------------- 不错,我要先学习下 --------------------编程问答-------------------- 语法错了,所有的操作是基于Adodc1.RecordSet的操作。你怎么直接用ACCESS来做操作呢,要先连接数据库,再形成数据集合也就是所说的Adodc1.RecordSet。基于这个对象才有Adodc1.RecordSet.AddNew操作。ACCESS.AddNew是什么啊?ACCESS是新的RecordSet示例化对象吗?还有一点,对RecordSet数据集合操作也在ADO控件激活之后,也是好所你把Adodc1.Refresh必须放在RecordSet操作前面
Dim rsTimetable As Recordset
Dim Index As Long
Dim STR As String
Dim S1 As String
Dim S2 As String
Dim S3 As String
Dim Sdate As Date
Dim Tdate As Date
Dim s As Boolean
Set dbBroadcast = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\Broadcast.mdb")
Set rsTimetable = dbBroadcast.OpenRecordset("广播内容", dbOpenDynaset)
s = False
Index = 1
Adodc2.Refresh
With Adodc2.Recordset
If Not (.EOF And .BOF) Then
.MoveFirst
Do
STR = .Fields("start_date") '修改图定日期参数
S1 = Left(STR, 4)
S2 = Left(Right(STR, 4), 2)
S3 = Right(STR, 2)
Sdate = DateValue(S1 & "-" & S2 & "-" & S3) '图定日期
STR = .Fields("train_date") '修改车次日期参数
S1 = Left(STR, 4)
S2 = Left(Right(STR, 4), 2)
S3 = Right(STR, 2)
Tdate = DateValue(S1 & "-" & S2 & "-" & S3) '车次日期
If (Not Sdate < Date Or Not Tdate < Date) Then
If (.Fields("transmit_flag") = 2 Or .Fields("transmit_flag") = 1) Then '修改数据
rsTimetable.FindFirst "车次='" & Trim(.Fields("train_code")) & "'" & " and 广播内容='" & Trim(.Fields("item_name")) & "'" & " and 广播日期='" & Tdate & "'"
' If rsTimetable.Fields("车次") <> "%" Then
If Not rsTimetable.NoMatch Then '找到则修改
rsTimetable.Edit
Else '找不到则增加数据
rsTimetable.AddNew
rsTimetable.Fields("序号") = Date & Time & Index
End If
rsTimetable.Fields("车次") = Trim(.Fields("train_code"))
rsTimetable.Fields("到点") = TimeValue(.Fields("fact_arrive_time"))
rsTimetable.Fields("开点") = TimeValue(.Fields("fact_start_time"))
rsTimetable.Fields("始发") = Trim(.Fields("start_station_name"))
rsTimetable.Fields("终到") = Trim(.Fields("end_station_name"))
If Not IsNull(.Fields("new_waiting")) Then
If InStr(Trim(.Fields("new_waiting")), "一楼候车室") <> 0 Then 'Or InStr(.Fields("new_waiting"), "北一候车室") <> 0 Then
If InStr(Trim(.Fields("new_waiting")), "二楼候车室") <> 0 Then 'Or InStr(.Fields("new_waiting"), "北二候车室") <> 0 Then
rsTimetable.Fields("候车室") = 1
rsTimetable.Fields("检票口") = 2
Else
rsTimetable.Fields("候车室") = 1
rsTimetable.Fields("检票口") = 0
End If
End If
If InStr(Trim(.Fields("new_waiting")), "二楼候车室") <> 0 Then ' Or InStr(.Fields("new_waiting"), "北二候车室") <> 0 Then
If InStr(Trim(.Fields("new_waiting")), "一楼候车室") <> 0 Then ' Or InStr(.Fields("new_waiting"), "北一候车室") <> 0 Then
rsTimetable.Fields("候车室") = 1
rsTimetable.Fields("检票口") = 2
Else
rsTimetable.Fields("候车室") = 2
rsTimetable.Fields("检票口") = 0
End If
End If
Else
If InStr(Trim(.Fields("waiting")), "一楼候车室") <> 0 Then ' Or InStr(.Fields("waiting"), "北一候车室") <> 0 Then
If InStr(Trim(.Fields("waiting")), "二楼候车室") <> 0 Then 'Or InStr(.Fields("waiting"), "北二候车室") <> 0 Then
rsTimetable.Fields("候车室") = 1
rsTimetable.Fields("检票口") = 2
Else
rsTimetable.Fields("候车室") = 1
rsTimetable.Fields("检票口") = 0
End If
End If
If InStr(Trim(.Fields("waiting")), "二楼候车室") <> 0 Then 'Or InStr(.Fields("waiting"), "北二候车室") <> 0 Then
If InStr(Trim(.Fields("waiting")), "一楼候车室") <> 0 Then ' Or InStr(.Fields("waiting"), "北一候车室") <> 0 Then
rsTimetable.Fields("候车室") = 1
rsTimetable.Fields("检票口") = 2
Else
rsTimetable.Fields("候车室") = 2
rsTimetable.Fields("检票口") = 0
End If
End If
End If
If Not IsNull(Trim(.Fields("new_gudao"))) Then
rsTimetable.Fields("股道") = Trim(.Fields("new_gudao"))
Else
rsTimetable.Fields("股道") = Trim(.Fields("gudao"))
End If
'
' rsTimetable.Fields("广播内容") = Trim(.Fields("item_name"))
If Not IsNull(Trim(.Fields("new_gudao"))) Then
If InStr(Trim(.Fields("item_name")), "列车进站") <> 0 Then
If Trim(.Fields("new_gudao")) = 8 Then
rsTimetable.Fields("广播区域") = "19"
ElseIf Trim(.Fields("new_gudao")) = 5 Then
rsTimetable.Fields("广播区域") = "3"
Else
rsTimetable.Fields("广播区域") = "4"
End If
Else
If Toolbar1.Buttons("SpecalBroadcast").Value = tbrUnpressed Then
rsTimetable.Fields("广播区域") = "13 15 21 22"
Else
rsTimetable.Fields("广播区域") = "1 2 6 13 15 21 22"
End If
End If
Else
If InStr(Trim(.Fields("item_name")), "列车进站") <> 0 Then
If Trim(.Fields("gudao")) = 8 Then
rsTimetable.Fields("广播区域") = "19"
ElseIf Trim(.Fields("gudao")) = 5 Then
rsTimetable.Fields("广播区域") = "3"
Else
rsTimetable.Fields("广播区域") = "4"
End If
Else
If Toolbar1.Buttons("SpecalBroadcast").Value = tbrUnpressed Then
rsTimetable.Fields("广播区域") = "13 15 21 22"
Else
rsTimetable.Fields("广播区域") = "1 2 6 13 15 21 22"
End If
End If
End If
rsTimetable.Fields("国语") = 1
rsTimetable.Fields("英语") = 0
rsTimetable.Fields("粤语") = 0
If (.Fields("run_count") = 0 Or IsNull(.Fields("run_count"))) Then
rsTimetable.Fields("连续广播次数") = 2
Else
rsTimetable.Fields("连续广播次数") = .Fields("run_count")
End If
rsTimetable.Fields("级别") = .Fields("run_prior")
rsTimetable.Fields("状态") = "未播"
rsTimetable.Fields("广播日期") = Tdate
rsTimetable.Fields("广播时间") = .Fields("run_time") & ":00"
rsTimetable.Fields("车次日期") = Sdate
rsTimetable.Fields("晚点") = ""
rsTimetable.Fields("广播内容") = .Fields("item_name")
rsTimetable.Update
.Fields("transmit_flag") = 8 '表示已经读取该条广播信息
s = True
.Update
Debug.Print .Fields("transmit_flag")
End If
End If
' End If
Index = Index + 1
.MoveNext
Loop Until .EOF
End If
End With
' RSDepart.Close
' RSArrival.Close
' RSVia.Close
rsTimetable.Close
dbBroadcast.Close
If s = True Then
Data1.DatabaseName = App.Path & "\" & "BROADCAST.MDB"
Adodc1.RecordSource = "select 序号,广播时间,车次,到点,开点,广播内容,始发,终到,股道,级别,晚点,状态,连续广播次数,广播区域,候车室,检票口,英语,国语,粤语,广播日期,车次日期,车次头 from 广播内容 order by cdate(广播日期),cdate(到点),车次,cdate(广播时间)"
Data1.RecordSource = "select 序号,广播时间,车次,到点,开点,广播内容,始发,终到,股道,级别,晚点,状态,连续广播次数,广播区域,候车室,检票口,英语,国语,粤语,广播日期,车次日期,车次头 from 广播内容 order by cdate(广播日期),cdate(到点),车次,cdate(广播时间)"
Data1.Refresh
Adodc1.Refresh
Adodc2.Refresh
HFlexGrid.Refresh
Call setFlexGrid_Disp
Timer5.Enabled = Auto_Broadcast '恢复自动广播
End If
补充:VB , 基础类