|
1、可用Create View
2、这里的解决办法是要为数据源的表定义主键,SQL Server表更新时要设置主键或主索引(或称唯一索引),否则无法在access调用时更新数据
能否这样理解,如果没有唯一索引, SQL 语句根本无从判定用 SQL 语句操作哪条数据
您的理解是正确的!在ADP中,如果您创建的表格中没有唯一索引/主键,您的表格将无法进行插入,删除或者更新的操作。
原因就是access所使用的Jet引擎无法判定SQL语句操作的是哪条语句。具体的描述这个问题文档如下:
235267 ACC2000: Table in a Microsoft access Project Cannot Be Updated
http://support.microsoft.com/?id=235267
另外,当您尝试更新某一条记录的时候,您也会在整个access 窗体的左下角状态栏中看到"The Recordset is not Updateable"的信息。产生这个问题的原因是一样的:
304179 ACC2000: Status Bar Displays "Recordset Not Updateable" Message When You
http://support.microsoft.com/?id=304179
综上,解决问题的办法是为ADP中的Table加上唯一索引,或者直接加上主键来标示每一个记录。
3、将数据类型更改为int,然后在识别栏打勾,识别种子设定为 1 ,识
别递增量设定为 1 即可。
4、谢谢各位高手的指点,虽然只有3个字(ADO)但对我帮助良多,现在
我正在查看有关 ADO 和 ADOX 的帮助,并且适应新的编程方法,原来用的是DAO编程,看来
现在要全部改过来才行了,顺便问一下,在DAO中用currentdb.openrecordset,在ADO中有否类似语句?
5、Execute 方法
6、使用以下过程
Sub ProcedureText()
Dim cnn As New ADODB.Connection
Dim cat As New ADOX.Catalog
Dim cmd As New ADODB.Command
' Open the Connection
cnn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Program Files\Microsoft Office\" & _
"Office\Samples\Northwind.mdb;"
' Open the catalog
Set cat.ActiveConnection = cnn
' Get the Command
Set cmd = cat.Procedures("CustomerById").Command
' Update the CommandText
cmd.CommandText = "Select CustomerId, CompanyName, ContactName " & _
"From Customers " & _
"Where CustomerId = [CustId]"
' Update the Procedure
Set cat.Procedures("CustomerById").Command = cmd
End Sub
|
7、用以下代码
Dim tbl As ADODB.Recordset, cn As ADODB.Connection
Set cn = CurrentProject.Connection
Set tbl = New ADODB.Recordset
tbl.ActiveConnection = cn
tbl.Open "TableName", cn, , adLockPessimistic, adCmdTable |
8、呵呵,ADO爆简单,代码如下:
Sub CreateDatabase()
Dim cat As New ADOX.Catalog
cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\new.mdb"
End Sub
|
当然,你必须先在引用里面选中"Microsoft ADO Ext. X.X for DDL and Security"
9、只完成了一部分,代码如下
Private Sub 导出_Click()
On Error GoTo Err_导出_click
Dim hShell As Long
Dim hProc As Long
Dim lExit As Long
Dim DirName1(3) As String
Dim FoundName1 As String
DirName1(1) = DBAppPath(1) & "\" & "winrar.exe"
DirName1(2) = DBAppPath(2)
FoundName1 = Dir(DirName1(1), vbNormal)
If FoundName1 = "" Then DirName1(0) = "Winrar文件未找到" & Chr(13)
FoundName1 = ""
FoundName1 = Dir(DirName1(2), vbDirectory)
If FoundName1 = "" Or FoundName1 = "." Then DirName1(0) = DirName1(0) & "compress 目录未建立" & Chr(13) & "请重新设定各项系统参数。"
If DirName1(0) <> "" Then
MsgBox "系统参数设置未完成:" & Chr(13) & DirName1(0) & Chr(13) & "请先进行参数设置!"
Exit Sub
End If
If (MsgBox("现在请先在软盘上做好标签,写上日期。" & Chr(13) & "如果您是要将数据备份至软盘,那么" & Chr(13) & "请确保以下位置:" & Chr(9) & DBAppPath(8) & Chr(9) & "没有您所需要的数据" & Chr(13) & "因为备份程序将清空其中所有文件及目录。" + Chr(13) + Chr(13) + Chr(13) + " 请确认现在是否执行导出操作?", 4, "是否开始导出...") = 6) Then
Else
Exit Sub
End If
Dim DirName As String, FoundName As String
DirName = DBAppPath(2) & "\" & DBAppPath(10)
FoundName = Dir(DirName, vbNormal)
If FoundName = "" Then
Else
MsgBox "现已检测到文件 " & DBAppPath(2) & "\" & DBAppPath(10) & "现在删除。可能您上次未成功,请检察!"
Kill DBAppPath(2) & "\" & DBAppPath(10)
End If
Dim fileName As String, CallShellText
Dim Cat As New ADOX.Catalog
Cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBAppPath(2) & "\" & DBAppPath(10)
'--------------------------------------------
Dim TDF As ADOX.Table, CN As ADODB.Connection
Set CN = CurrentProject.Connection
Set Cat.ActiveConnection = CN
For Each TDF In Cat.Tables
'Debug.Print TDF.Type & "--------" & TDF.Name
If TDF.Type = "Table" Then
'Debug.Print TDF.Type & "--------" & TDF.Name
DoCmd.TransferDatabase acExport, "microsoft access", DBAppPath(2) & "\" & DBAppPath(10), acTable, TDF.Name, TDF.Name, False
End If
Next TDF
'注意Application.CurrentProject.Path 的用法
Dim BackupToFile As String
'以下一段主要是判定输出的驱动器是何种类型,以便用不同的命令行来生成压缩包,
'写下面一段的原因,主要是因为将数据库以多卷压缩的形式输出到硬盘上行不通,因为如果硬盘上已经存在一个
'压缩包,那么WinRAR就无法对这个压缩包进行更新
Dim fs, d, t
Set fs = CreateObject("Scripting.FileSystemObject")
Set d = fs.GetDrive(fs.getdrivename(DBAppPath(2)))
Select Case d.DriveType
Case 0
t = "Unknown"
Case 1
t = "Removable"
BackupToFile = Chr(34) & DBAppPath(1) & "\winrar.exe" & Chr(34) & " m -vf -vd -vn " & Chr(34) & DBAppPath(8) & "\" & DBAppPath(9) & Chr(34) & " " & Chr(34) & DBAppPath(2) & "\" & DBAppPath(10) & Chr(34)
Case 2
t = "Fixed"
BackupToFile = Chr(34) & DBAppPath(1) & "\winrar.exe" & Chr(34) & " m " & Chr(34) & DBAppPath(8) & "\" & DBAppPath(9) & Chr(34) & " " & Chr(34) & DBAppPath(2) & "\" & DBAppPath(10) & Chr(34)
Case 3
t = "Network"
BackupToFile = Chr(34) & DBAppPath(1) & "\winrar.exe" & Chr(34) & " m " & Chr(34) & DBAppPath(8) & "\" & DBAppPath(9) & Chr(34) & " " & Chr(34) & DBAppPath(2) & "\" & DBAppPath(10) & Chr(34)
Case 4
t = "CD-ROM"
Case 5
t = "RAM Disk"
End Select
'BackupToFile = Chr(34) & dbapppath(1) & "\winrar.exe" & Chr(34) & " m -v1300 -vd -vn " & Chr(34) & dbapppath(8) & "\" & dbapppath(9) & Chr(34) & " " & Chr(34) & dbapppath(2) & "\" & dbapppath(10) & Chr(34)
hShell = Shell(BackupToFile, 1)
hProc = OpenProcess(PROCESS_QUERY_INFORMATION, False, hShell)
If hShell = 0 Then MsgBox "程序执行失败"
Do
GetExitCodeProcess hProc, lExit
DoEvents
Loop While lExit = STILL_ACTIVE
MsgBox "导出已经完成,请检查磁盘"
Exit_导出_click:
Exit Sub
Err_导出_click:
MsgBox Err.Description
Resume Exit_导出_click
End Sub
|
10、这是仅仅是因为现在后台是SQLSERVER,而不再是MDB了,关于如何修改View中的SQL文本,请到SQLSERVER的Books Online中查阅关键字:ALTER VIEW。
11、可以,用access做前台,sqlserver做后台开发,开发方式有好几种:
adp+sqlserver:使用access项目+sqlserver进行开发,可以直接操作table,procedure等,但是所有的存储过程、视图、自定义函数、触发器都是t-sql的。
mdb(link table)+sqlserver:使用链接表,链接sqlserver进行开发,你可以最大限度的保留先前基于mdb的程序
mdb(ado)+sqlserver:不使用任何表,完全将Access作为前台,用ado来操作sqlserver,这是目前为止access操作sqlserver最安全的一种方式。
|