|
本帖最后由 zjszjs27 于 2012-9-5 20:44 编辑
- LineText = FileText.readline
-
- ''''''''''''''''''''''''''''''''''''按行读取的记录,如果不是已"/"开始的,进行处理'''''''''''''''''''''''''''''
-
-
- If (Left(LineText, 1) <> "/" And LineText <> "") Then '---------------------(2)--------------------------------
- '获取BSC名称,只在第一行有效数据中出现,才会获取BSC名称
- If bsc_search_biaoji = True And InStr(LineText, "SET SYS") Then
- BscName = Mid(LineText, InStr(LineText, "SYSOBJECTID") + 13, InStr(InStr(LineText, "SYSOBJECTID") + 13, LineText, ",") - 2 - (InStr(LineText, "SYSOBJECTID") + 13) + 1)
- End If
- '获取列名和列值\表名空格间隔形式
- linetext_str = str_sp(LineText, ",", ":")
- '获取表名
- tableName = Replace(linetext_str(0), " ", "_")
-
- colon_name = ""
- colon_value = ""
- If dic_tbl.Exists(tableName) = False Then '---------------------(1)--------------------------------
- ''''''''''''''''''''''''''''''''''''''查找需要创建的表是否已经在数据库中'''''''''''''''''''''''''''''''''''''''
-
- '该表不存在,则创建表,并增加所有列
- '''''''''''''''''''查询结果,在数据库中没有找到需创建的表,所以进行创建新表的操作'''''''''''''''''''''''''''
- dic_value = "-"
- '创建表,默认包含一列BSC_NAME
- sql_str = "create table " & tableName & " (" & "HBSC_NAME" & " text(255))"
- CurrentProject.Connection.Execute sql_str
- For I = LBound(linetext_str) + 1 To UBound(linetext_str) Step 2
- '获取列名和列值
- colon_name = colon_name & ", " & linetext_str(I)
- colon_value = colon_value & ", " & """" & linetext_str(I + 1) & """"
- '创建各列
- If (Len(linetext_str(I + 1)) <= 255) Then
- sql_str = "Alter Table " & tableName & " Add " & "COLUMN " & linetext_str(I) & " text(255)"
- CurrentProject.Connection.Execute sql_str
-
- Else
- sql_str = "Alter Table " & tableName & " Add " & "COLUMN " & linetext_str(I) & " longtext"
- CurrentProject.Connection.Execute sql_str
-
- End If
- dic_value = dic_value & linetext_str(I) & "-"
- Next I
- dic_tbl.Add tableName, dic_value
- Else '--------------------(1)-----------------------------------------
- '该表存在,则判断各列是否都存在,不存在的增加列
-
- For I = LBound(linetext_str) + 1 To UBound(linetext_str) Step 2
- '获取列名和列值
- colon_name = colon_name & ", " & linetext_str(I)
- colon_value = colon_value & ", " & """" & linetext_str(I + 1) & """"
- '判断列名在表中是否存在
- If InStr(dic_tbl.Item(tableName), linetext_str(I)) = 0 Then '不存在
- '更新字典中列名值
- dic_tbl.Item(tableName) = dic_tbl.Item(tableName) & linetext_str(I) & "-"
- '在表中增加缺少的列
- If (Len(linetext_str(I + 1)) <= 255) Then
- sql_str = "Alter Table " & tableName & " Add " & "COLUMN " & linetext_str(I) & " text(255)"
- 运行出错的地方: CurrentProject.Connection.Execute sql_str
- Else
- sql_str = "Alter Table " & tableName & " Add " & "COLUMN " & linetext_str(I) & " longtext"
- CurrentProject.Connection.Execute sql_str
- End If
- Else
- find_colomn_biaoji = False
- m = InStr(dic_tbl.Item(tableName), linetext_str(I))
- Do While m + Len(linetext_str(I)) - 1 <= Len(dic_tbl.Item(tableName))
- '获取M位前一位字符
- temp_str1 = Mid(dic_tbl.Item(tableName), m - 1, 1)
- '获取M+LEN()后一位字符
- temp_str2 = Mid(dic_tbl.Item(tableName), m + Len(linetext_str(I)), 1)
- '当两者均为“-”时,说明完全匹配,否则匹配失败
- If temp_str1 = "-" And temp_str2 = "-" Then
- find_colomn_biaoji = True
- Exit Do
- Else
- m = InStr(m + Len(linetext_str(I)), dic_tbl.Item(tableName), linetext_str(I))
- If m = 0 Then
- Exit Do
- End If
- End If
- Loop
- If find_colomn_biaoji = False Then
- '更新字典中列名值
- dic_tbl.Item(tableName) = dic_tbl.Item(tableName) & linetext_str(I) & "-"
- '在表中增加缺少的列
- If (Len(linetext_str(I + 1)) <= 255) Then
- sql_str = "Alter Table " & tableName & " Add " & "COLUMN " & linetext_str(I) & " text(255)"
- CurrentProject.Connection.Execute sql_str
- Else
- sql_str = "Alter Table " & tableName & " Add " & "COLUMN " & linetext_str(I) & " longtext"
- CurrentProject.Connection.Execute sql_str
- End If
- End If
-
- End If
-
- Next I
- End If '--------------------(1)-----------------------------------------
-
- '将所有列值插入到表中
-
- '默认创建的表中包含HBSC_NAME列,故需增加列HBSC_NAME及其对应的值BscName
- insertSQL1 = "insert into " & tableName & "(HBSC_NAME"
- insertSQL2 = " values(" & """" & BscName & """"
- sql_str = insertSQL1 & colon_name & ")" & insertSQL2 & colon_value & ")"
- CurrentProject.Connection.Execute sql_str
-
- End If '---------------------(2)--------------------------------
复制代码 运行到”运行出错的地方“,提示表被其他用户或进程使用。这个表是已经存在的,之前已经插入两行数据,第三行数据比表中多了一列,所以在这增加一列,就在这出错了。请问哪里代码有问题啊,应该怎么修改啊?我程序里就是多次运行了语句 CurrentProject.Connection.Execute sql_str,对这个有什么要求吗?
|
|