<bdo id='q6URy'></bdo><ul id='q6URy'></ul>

    <tfoot id='q6URy'></tfoot>

    <small id='q6URy'></small><noframes id='q6URy'>

    <legend id='q6URy'><style id='q6URy'><dir id='q6URy'><q id='q6URy'></q></dir></style></legend>

    <i id='q6URy'><tr id='q6URy'><dt id='q6URy'><q id='q6URy'><span id='q6URy'><b id='q6URy'><form id='q6URy'><ins id='q6URy'></ins><ul id='q6URy'></ul><sub id='q6URy'></sub></form><legend id='q6URy'></legend><bdo id='q6URy'><pre id='q6URy'><center id='q6URy'></center></pre></bdo></b><th id='q6URy'></th></span></q></dt></tr></i><div id='q6URy'><tfoot id='q6URy'></tfoot><dl id='q6URy'><fieldset id='q6URy'></fieldset></dl></div>
    1. 与 CreateTableDef 链接时如何设置主键

      How to set primary key when linking with CreateTableDef(与 CreateTableDef 链接时如何设置主键)
      1. <small id='bLJCf'></small><noframes id='bLJCf'>

          <tbody id='bLJCf'></tbody>
        <i id='bLJCf'><tr id='bLJCf'><dt id='bLJCf'><q id='bLJCf'><span id='bLJCf'><b id='bLJCf'><form id='bLJCf'><ins id='bLJCf'></ins><ul id='bLJCf'></ul><sub id='bLJCf'></sub></form><legend id='bLJCf'></legend><bdo id='bLJCf'><pre id='bLJCf'><center id='bLJCf'></center></pre></bdo></b><th id='bLJCf'></th></span></q></dt></tr></i><div id='bLJCf'><tfoot id='bLJCf'></tfoot><dl id='bLJCf'><fieldset id='bLJCf'></fieldset></dl></div>

                <bdo id='bLJCf'></bdo><ul id='bLJCf'></ul>
                <tfoot id='bLJCf'></tfoot>
              • <legend id='bLJCf'><style id='bLJCf'><dir id='bLJCf'><q id='bLJCf'></q></dir></style></legend>
                本文介绍了与 CreateTableDef 链接时如何设置主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在 MS Access 数据库中,我像这样连接到 SQL Server 数据库中的视图:

                In a MS Access database, I'm connecting to views in a SQL Server database like this:

                Dim s  As String
                s = "ODBC;DSN=mydb;Trusted_Connection=Yes;DATABASE=mydb;"
                
                Dim td As TableDef
                Set td = CurrentDb.CreateTableDef("vwMyView", 0, "MySchema.vwMyView", s)
                
                CurrentDb.TableDefs.Append td
                CurrentDb.TableDefs.Refresh
                

                这将创建一个链接表,该表链接到 SQL Server 中的视图.

                This creates a linked table, which is linked to a view in SQL Server.

                但是,我无法插入/更新/删除,因为 Access 不知道主键".VBA中如何添加主键信息?

                However, I cannot insert/update/delete, because Access does not know the "primary key". How can the information about the primary key added in VBA ?

                使用链接表向导时,总是会要求您从列表框中选择唯一键列.我想在 VBA 中重现这种行为.

                When using the Linked Table Wizard, you are always asked to select the unique key columns from a listbox. I want to reproduce this behaviour in VBA.

                推荐答案

                您可以随时更新刚刚附加的表以包含索引/主键.类似的东西,

                You can always update the table you just attached to include an Index/Primary key. Something like,

                Dim s  As String
                s = "ODBC;DSN=mydb;Trusted_Connection=Yes;DATABASE=mydb;"
                
                Dim td As TableDef
                Set td = CurrentDb.CreateTableDef("vwMyView", 0, "MySchema.vwMyView", s)
                
                CurrentDb.TableDefs.Append td
                
                CurrentDb.Execute "CREATE UNIQUE INDEX SomeIndex ON vwMyView (PrimaryKeyColumn) WITH PRIMARY".
                
                CurrentDb.TableDefs.Refresh
                
                Set td = Nothing
                

                不确定是否需要在创建 INDEX 之前刷新 CurrentDB.首先尝试刷新,如果它不起作用 - 刷新它然后执行 CREATE 语句.

                Not sure if you need to refresh the CurrentDB before creating an INDEX. Try refreshing without first, if it does not work - refresh it then Execute the CREATE statement.

                这篇关于与 CreateTableDef 链接时如何设置主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Building a comma separated list?(建立一个逗号分隔的列表?)
                Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)
                  <bdo id='NdLvy'></bdo><ul id='NdLvy'></ul>

                    <legend id='NdLvy'><style id='NdLvy'><dir id='NdLvy'><q id='NdLvy'></q></dir></style></legend>

                    <small id='NdLvy'></small><noframes id='NdLvy'>

                    <tfoot id='NdLvy'></tfoot>
                  1. <i id='NdLvy'><tr id='NdLvy'><dt id='NdLvy'><q id='NdLvy'><span id='NdLvy'><b id='NdLvy'><form id='NdLvy'><ins id='NdLvy'></ins><ul id='NdLvy'></ul><sub id='NdLvy'></sub></form><legend id='NdLvy'></legend><bdo id='NdLvy'><pre id='NdLvy'><center id='NdLvy'></center></pre></bdo></b><th id='NdLvy'></th></span></q></dt></tr></i><div id='NdLvy'><tfoot id='NdLvy'></tfoot><dl id='NdLvy'><fieldset id='NdLvy'></fieldset></dl></div>

                          <tbody id='NdLvy'></tbody>