主题:关于ACCESS数据库 复制问题
我在利用VB的ADO对ACCESS数据进行复制时,出现了这样的问题:第一条记录怎么都复制不了!复制的内容是从第二条到最后一条,始终把第一条复制不过去,求教各位大虾,问题在哪?代码如下:
Dim date1 As String
Dim pstr As String
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim column As New ADOX.column
Dim sj As String
Dim conn As ADODB.Connection
Dim re As ADODB.Recordset
date1 = Format(Date, "YYYYMMDD")
j = "AKS" & date1
pstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:\数据库\" & sj & ".mdb"
Dim FileName As String
FileName = Dir("f:\数据库\" & sj & ".mdb")
If FileName <> "" Then Kill "f:\数据库\" & sj & ".mdb"""
cat.Create pstr '创建数据库
cat.ActiveConnection = pstr
tbl.Name = "GTCurveData" '表的名称
column.ParentCatalog = cat
column.Name = "序号"
column.Type = adInteger
'column.Properties("AutoIncrement").Value = True
tbl.Columns.Append column, adInteger
tbl.Keys.Append "FirstPrimaryKey", adKeyPrimary, column
tbl.Columns.Append "井号", adVarWChar, 50
tbl.Columns("井号").Attributes = adColNullable
tbl.Columns.Append "测试时间", adDate
tbl.Columns("测试时间").Attributes = adColNullable
tbl.Columns.Append "冲程", adSingle
tbl.Columns("冲程").Attributes = adColNullable
tbl.Columns.Append "冲次", adSingle
tbl.Columns("冲次").Attributes = adColNullable
tbl.Columns.Append "示功图数据", adLongVarBinary
tbl.Columns("示功图数据").Attributes = adColNullable
tbl.Columns.Append "最大载荷", adSingle
tbl.Columns("最大载荷").Attributes = adColNullable
tbl.Columns.Append "最小载荷", adSingle
tbl.Columns("最小载荷").Attributes = adColNullable
tbl.Columns.Append "载荷溢出", adVarWChar, 20
tbl.Columns("载荷溢出").Attributes = adColNullable
tbl.Columns.Append "位移溢出", adVarWChar, 20
tbl.Columns("位移溢出").Attributes = adColNullable
cat.Tables.Append tbl '建立数据表
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:\数据库\" & sj & ".mdb;Persist Security Info=False"
conn.Open
Set re = New ADODB.Recordset
re.CursorLocation = adUseClient
re.Open "GTCurveData", conn, adOpenKeyset, adLockPessimistic
Set myconn = New ADODB.Connection
myconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\我的文档\桌面\示功图采集服务软件\功图数据缓存.mdb;Persist Security Info=False"
myconn.Open
Set myrecord = New ADODB.Recordset
myrecord.CursorLocation = adUseClient
myrecord.Open "gotu", myconn, adOpenKeyset, adLockPessimistic
myrecord.MoveFirst
Text1.Text = myrecord.RecordCount
Dim i As Integer
For i = 1 To myrecord.RecordCount
re.AddNew
re!序号 = i
re!井号 = myrecord!井号
re!测试时间 = myrecord!测试时间
re!冲程 = myrecord!冲程
re!冲次 = myrecord!冲次
re!示功图数据 = myrecord!示功图数据
re!最大载荷 = myrecord!最大载荷
re!最小载荷 = myrecord!最小载荷
re!载荷溢出 = myrecord!载荷溢出
re!位移溢出 = myrecord!位移溢出
re.Update
myrecord.MoveNext
Next i
Dim date1 As String
Dim pstr As String
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim column As New ADOX.column
Dim sj As String
Dim conn As ADODB.Connection
Dim re As ADODB.Recordset
date1 = Format(Date, "YYYYMMDD")
j = "AKS" & date1
pstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:\数据库\" & sj & ".mdb"
Dim FileName As String
FileName = Dir("f:\数据库\" & sj & ".mdb")
If FileName <> "" Then Kill "f:\数据库\" & sj & ".mdb"""
cat.Create pstr '创建数据库
cat.ActiveConnection = pstr
tbl.Name = "GTCurveData" '表的名称
column.ParentCatalog = cat
column.Name = "序号"
column.Type = adInteger
'column.Properties("AutoIncrement").Value = True
tbl.Columns.Append column, adInteger
tbl.Keys.Append "FirstPrimaryKey", adKeyPrimary, column
tbl.Columns.Append "井号", adVarWChar, 50
tbl.Columns("井号").Attributes = adColNullable
tbl.Columns.Append "测试时间", adDate
tbl.Columns("测试时间").Attributes = adColNullable
tbl.Columns.Append "冲程", adSingle
tbl.Columns("冲程").Attributes = adColNullable
tbl.Columns.Append "冲次", adSingle
tbl.Columns("冲次").Attributes = adColNullable
tbl.Columns.Append "示功图数据", adLongVarBinary
tbl.Columns("示功图数据").Attributes = adColNullable
tbl.Columns.Append "最大载荷", adSingle
tbl.Columns("最大载荷").Attributes = adColNullable
tbl.Columns.Append "最小载荷", adSingle
tbl.Columns("最小载荷").Attributes = adColNullable
tbl.Columns.Append "载荷溢出", adVarWChar, 20
tbl.Columns("载荷溢出").Attributes = adColNullable
tbl.Columns.Append "位移溢出", adVarWChar, 20
tbl.Columns("位移溢出").Attributes = adColNullable
cat.Tables.Append tbl '建立数据表
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:\数据库\" & sj & ".mdb;Persist Security Info=False"
conn.Open
Set re = New ADODB.Recordset
re.CursorLocation = adUseClient
re.Open "GTCurveData", conn, adOpenKeyset, adLockPessimistic
Set myconn = New ADODB.Connection
myconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\我的文档\桌面\示功图采集服务软件\功图数据缓存.mdb;Persist Security Info=False"
myconn.Open
Set myrecord = New ADODB.Recordset
myrecord.CursorLocation = adUseClient
myrecord.Open "gotu", myconn, adOpenKeyset, adLockPessimistic
myrecord.MoveFirst
Text1.Text = myrecord.RecordCount
Dim i As Integer
For i = 1 To myrecord.RecordCount
re.AddNew
re!序号 = i
re!井号 = myrecord!井号
re!测试时间 = myrecord!测试时间
re!冲程 = myrecord!冲程
re!冲次 = myrecord!冲次
re!示功图数据 = myrecord!示功图数据
re!最大载荷 = myrecord!最大载荷
re!最小载荷 = myrecord!最小载荷
re!载荷溢出 = myrecord!载荷溢出
re!位移溢出 = myrecord!位移溢出
re.Update
myrecord.MoveNext
Next i