powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Microsoft Access [игнор отключен] [закрыт для гостей] / Можно ли изменять БД через АДО, если код расположен в самой БД?
2 сообщений из 2, страница 1 из 1
Можно ли изменять БД через АДО, если код расположен в самой БД?
    #32144524
Copper_Kettle
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Вот, стащил с форума utteraccess пример по созданию таблицы в базе
через АДО. Там таблица создавалась в отдельной, временной БД.
Изменил ее так, чтобы таблица создавалась в самой БД.
Вроде все работает, но если хоть букву изменить в коде функции,
даже если поставить комментарий, и после этого запустить,
то выдается ощибка:
"База данных была приведена пользователем ".." на компьютере ".." в
состояние, препятствующее ее открытию или блокировке.

Что я тут сделал не так и где прочитать, как сделать это правильно?
MSDN уже обчитался.
Дайте пожалуйста, ссылку, что еще почитать.
Заранее благодарю :0)






Sub AddTable()
Dim conn As ADODB.Connection
Dim objCat As ADOX.Catalog
Dim objTbl As ADOX.Table
Dim tbl As ADOX.Table
Dim objCol As ADOX.Column
Dim DBPath As String
Dim strTblName As String
Set conn = New ADODB.Connection
Set objCat = New ADOX.Catalog
Set objTbl = New ADOX.Table
'The location of the TempDB gets assigned to a variable:
DBPath = Application.CurrentProject.Path & "\temp.mdb" '
strTblName = "temptable"
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & DBPath
objCat.ActiveConnection = conn
Set objTbl.ParentCatalog = objCat
'Create a new table in the tempDB'
With objTbl
For Each tbl In objCat.Tables 'first check if the table already exists:
If tbl.Name = strTblName Then
'clean up and exit if the table already exists
Set objCat = Nothing
Set objTbl = Nothing
Set conn = Nothing
Exit Sub
End If
Next
.Name = "Table" 'give the table a name
'This next few lines add fields to the table, this is method ONE
.Columns.Append "INT", adInteger 'add the FK
.Columns.Append "DATE", adDate 'date field
.Columns.Append "TXT", adLongVarWChar 'memo
.Columns.Append "FullName", adVarWChar, 150 'add the field FullName, NOTE: This value is required!
Set objCol = New ADOX.Column
'This next few lines add a text field to the table, this is method TWO
With objCol
'Add a field which can hold text
.Name = "TestField"
.DefinedSize = 50 '50 characters wide
.Type = adVarWChar 'Text
.Attributes = adColNullable 'This field is not required!!
End With
objTbl.Columns.Append objCol
Set objCol = Nothing
'Set objCol = New ADOX.Column
'This next few lines add a text field to the table, this is method TWO
'With objCol
'Add an autonumberfield
' .Name = "PrimaryKey"
' .Type = adInteger
'End With
'objTbl.Columns.Append objCol
Set objCol = Nothing
'After appending the column, set the autonumber property
'With !PrimaryKey
' Set .ParentCatalog = objCat
' .Properties("Autoincrement") = True
' .Properties("seed") = 1
' .Properties("increment") = 1
'End With
objCat.Tables.Append objTbl 'append the table to the tempDB
objCat.Tables.Refresh
Set objCat = Nothing
conn.Close
Set conn = Nothing
End With
End Sub
...
Рейтинг: 0 / 0
Можно ли изменять БД через АДО, если код расположен в самой БД?
    #32144630
Copper_Kettle
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Доперло. Я просто не сохранял код перед тем, как его выполнить.
Даа...
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / Microsoft Access [игнор отключен] [закрыт для гостей] / Можно ли изменять БД через АДО, если код расположен в самой БД?
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]