vb与ACCESS数据库
本帖最后由 bcrun 于 2013-11-30 12:00:47 编辑 http://my.csdn.net/my/album/detail/1658630#1658630
ACCESS数据库中建立的表
http://my.csdn.net/my/album/detail/1658630#1658632
txt文本中的数据格式,红色标记部分是想要导入到数据库表中的内容。
Private Sub InputDelay_Click()access 数据库 vb
Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=VisssimData.mdb"
cnn.ConnectionTimeout = 30
cnn.Open
Dim sSql As String
Dim fileRoute, vlrFilePath As String
Dim id, TIME, NO, Car, CarType, Delay As String
Dim x As Integer
fileRoute = Form2仿真文件选择.SimFileRoute.Text
If fileRoute = "" Then
Beep
MsgBox "请指定仿真文件路径", vbExclamation + vbOKOnly, "提示"
Exit Sub
End If
x = InStr(fileRoute, ".")
vlrFilePath = Left$(fileRoute, x - 1) + ".vlr"
Open vlrFilePath For Input As #1
Do While Not EOF(1)
Input #1, TIME, NO, Car, CarType, Delay
sSql = "insert into CompileDelay(ID,TIME, NO, Car, CarType, Delay) values (ID,TIME , TrimNO ,Car,CarType ,Delay)"
cnn.Execute (sSql)
Loop
Close #1
MsgBox "完成"
Set cnn = Nothing
End Sub