首页 \ 问答 \ 从Excel通过VBA到Access的SQL查询(特定于日期)(SQL Query from Excel via VBA to Access (date specific))

从Excel通过VBA到Access的SQL查询(特定于日期)(SQL Query from Excel via VBA to Access (date specific))

出于测试目的,我试图使用vba和SQL(方向:Excel + VBA访问)从MS Access表中获取一些数据到Excel中的记录集。

MS Access表称为T_Zeiten ,一列称为zeiDat ,其中包含日期(欧洲风格,如09.11.2016)。

我想要做的是打开一个连接,查找两个特定日期之间的所有条目,并将它们写入记录集。 我已经设法打开一个连接,但很难与日期的东西(美式日期)。 Excel中的“发件人”和“收件人”日期也格式化为“dd.mm.yyyy”。

这是我到目前为止:

Dim cn As Object
Dim ZeitenArbeitenGrob As Recordset
Dim strSqlZeitenArbeitenGrob As String
Dim start As String
Dim ende As String
start = Application.WorksheetFunction.Text(Cells(3, 2), "dd/mm/yyyy")
ende = Application.WorksheetFunction.Text(Cells(4, 2), "dd/mm/yyyy")
Dim strConnection As String
celllocation = 6
Set cn = CreateObject("ADODB.Connection")
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Users\mj\Downloads\Neuer Ordner (2)\ZeitErfKonst.mdb"
strSqlZeitenArbeitenGrob = "SELECT COUNT(zeiDat) FROM T_Zeiten WHERE [zeiDat] BETWEEN #" & start & "# And #" & ende & "#"
cn.Open strConnection
Set ZeitenArbeitenGrob = cn.Execute(strSqlZeitenArbeitenGrob)
MsgBox ZeitenArbeitenGrob.Fields(0)

有15个条目,但消息框显示我213,我不知道为什么。


For testing purposes, I am trying to get some data from an MS Access table to a recordset in Excel using vba and SQL (direction: Excel + VBA to Access).

The MS Access table is called T_Zeiten and one column is called zeiDat which contains dates (European style like 09.11.2016).

What I want to do is opening a connection, look for all entries between two specific dates and write them to a recordset. I already managed to open a connection but struggle with the date stuff (US-style dates). The "From" and "To" dates in Excel are also formatted as "dd.mm.yyyy".

This is what I have so far:

Dim cn As Object
Dim ZeitenArbeitenGrob As Recordset
Dim strSqlZeitenArbeitenGrob As String
Dim start As String
Dim ende As String
start = Application.WorksheetFunction.Text(Cells(3, 2), "dd/mm/yyyy")
ende = Application.WorksheetFunction.Text(Cells(4, 2), "dd/mm/yyyy")
Dim strConnection As String
celllocation = 6
Set cn = CreateObject("ADODB.Connection")
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Users\mj\Downloads\Neuer Ordner (2)\ZeitErfKonst.mdb"
strSqlZeitenArbeitenGrob = "SELECT COUNT(zeiDat) FROM T_Zeiten WHERE [zeiDat] BETWEEN #" & start & "# And #" & ende & "#"
cn.Open strConnection
Set ZeitenArbeitenGrob = cn.Execute(strSqlZeitenArbeitenGrob)
MsgBox ZeitenArbeitenGrob.Fields(0)

There are 15 entries but the messagebox shows me 213 and I don't know why.


原文:https://stackoverflow.com/questions/40501651
更新时间:2023-09-21 19:09

最满意答案

看来你在同一时间问两个问题。 仅代码与模型优先和EntityObject父类型与任意父类型。 无论父类型如何,您都可以通过模型优先获得设计器支持。 除了设计器支持,您还可以使用模型优先的预编译视图。 这可以显着提高性能。

EntityObject作为父对象可以优于所谓的“POCO”(通常是代理库,而不是“普通”对象),因为实体的运行时类型是您期望的确切类型,而不是运行时生成的亚型。

此外,与其他支持LINQ的ORM不同,实体框架具有丰富的LINQ支持,允许您投影真正的 POCO类型。 因此,可以构建真正的持久性无知的演示,而无需关心实体的基本类型。 您不会受到ORM黑盒中出现的任何类型的困扰。

EntityObject允许持久保存到数据库的私有属性。 使用代理类型要求这些属性至少受到保护且必须是虚拟的。 因此, EntityObject可以允许更好的封装。

顺便说一句,我并不是想建议使用代理没有优势; 我只想回答你关于EntityObject的优点是什么的问题。


You're asking two questions at the same time, it seems. Code-only versus model-first and EntityObject parent type versus arbitrary parent type. You get designer support with model-first, regardless of parent type. Aside from designer support, you can also use precompiled views with model-first. That can significantly help performance.

Having EntityObject as a parent can be an advantage over so-called "POCOs" (which are usually proxy bases, not "plain" objects), because the runtime type of your entities are the exact type you expect, rather than a runtime-generated subtype.

Also, unlike other ORMs which have minimal to no LINQ support, the Entity Framework has rich LINQ support, allowing you to project onto real POCO types. Therefore, it is possible to build truly persistence-ignorant presentations without having to care about what the base type of your entities are. You are not stuck with whatever type comes out of the ORM blackbox.

EntityObject allows for private properties which are persisted to the database. Using proxy types requires that those properties are at least protected and must be virtual. Therefore, EntityObject may allow for better encapsulation.

I'm not trying to suggest, by the way, that there aren't advantages to using proxies; I'm just trying to answer your question about what the advantages of EntityObject are.

相关问答

更多
  • 你可以尝试Automapper,适合我。 http://www.codeplex.com/AutoMapper You can try Automapper, works for me. http://www.codeplex.com/AutoMapper
  • 你真的确定你的CanAdd代码真的有效吗? 您将两个新对象附加到上下文,这意味着它们处于未更改状态。 通过调用SaveChanges,不应插入它们。 如果使用AddObject而不是Attach,则新的和父类别将设置为Added状态,并且两者都将插入SaveChanges。 您的CanUpdate方法不起作用,因为您只是将更新的类别设置为已修改状态,但您已附加了三个对象 - 类别,父类别以及它们之间的关系。 您还必须更改关系的状态。 Are you really sure that your CanAdd ...
  • 你实际上回答了你自己的问题。 要走的路是修改T4模板并添加您所需的支持级别。 如果您在不使用T4模板或由自我追踪实体生成器(另一个T4模板)生成的类时需要灵感检查由实体设计器生成的默认类 - 它们也应该使用OnPropertyChanged 。 You actually answered your own question. The way to go is modifying T4 template and add level of support you need. If you need some i ...
  • 我们有一个非常相似的情况,一个庞大的遗留DB2数据库,我们需要为我们的应用程序提供一小部分特定的表。 为此,我们使用实体框架代码的第一个模型来处理我们感兴趣的数据的相关子部分。这意味着我们可以做一些重要的事情: 从模型中删除不相关的数据,使代码更容易被发现 重命名模型中的字段,并将它们映射到应用程序中有意义的名称,而不是现有的列名称 减少查询所撤回的数据量(即我们的选择不会占用所有额外的位) 其中存在2种数据格式使用现代标准而不是历史格式 这对我们来说非常好,但有几点需要注意: 如果您正在撰写,请确保在模型 ...
  • POCO可以是你的域对象,因为它是持久无知的。 我没有看到任何理由为持久性创建单独的对象集和为域对象单独设置。 存储库是基础结构层的一部分。 POCO can be your domain object because it is persistance ignorant. I don't see any reason to create separate set of objects for persistance and separate set for domain objects. Reposito ...
  • 好吧,因为我正在使用非代理(使那个词起来......呀)“基于快照的变更跟踪”的方法,系统并没有真正的想法,它已经改变。 在此示例中,Customer是纯POCO类型。 与基于EntityObject或IPOCO的实体不同,对实体进行更改不会自动使状态管理器保持同步,因为纯POCO实体和实体框架之间没有自动通知。 因此,在查询状态管理器时,它认为客户对象状态是未更改的,即使我们已明确地对实体上的某个属性进行了更改。 从这里得到了 因此,为了确保它知道检查是否有更改,我必须使用AcceptChanges方法的 ...
  • EF不提供丢弃更改。 EF也没有二级缓存,因此一旦您配置了带有更改的上下文并创建了一个新的上下文来从数据库加载数据,您将获得未更改的数据。 这里的问题是实体框架缓存事物和旧对象留在旧上下文中,如果用户单击取消然后再次编辑并单击保存,我会得到例外。 当用户单击取消时,您必须丢弃编辑中使用的所有对象及其上下文。 这些对象和上下文已经死了。 用户再次单击编辑后,必须再次从数据库加载所有内容。 刷新导航属性不能很好地工作。 例如,一旦向导航集合添加内容,就不会通过从数据库刷新来删除它。 EF doesn't off ...
  • 看来你在同一时间问两个问题。 仅代码与模型优先和EntityObject父类型与任意父类型。 无论父类型如何,您都可以通过模型优先获得设计器支持。 除了设计器支持,您还可以使用模型优先的预编译视图。 这可以显着提高性能。 将EntityObject作为父对象可以优于所谓的“POCO”(通常是代理库,而不是“普通”对象),因为实体的运行时类型是您期望的确切类型,而不是运行时生成的亚型。 此外,与其他支持LINQ的ORM不同,实体框架具有丰富的LINQ支持,允许您投影到真正的 POCO类型。 因此,可以构建真正 ...
  • 示例如何按照复杂性顺序将实体框架4置于n层架构中: http://devtalk.dk/2009/06/09/Entity+Framework+40+Beta+1+POCO+ObjectSet+Repository+And+UnitOfWork.aspx http://blog.keithpatton.com/2009/05/30/Entity+Framework+POCO+Repository+Using+Visual+Studio+2010+Net+40+Beta+1.aspx http://danie ...
  • DataContractSerializer不读取外部元数据类型的属性。 并非.NET框架的每个功能都与API的其余部分一起工作,特别是较新的功能通常不适用于旧的功能,这正是这种情况。 最好的方法是使用IXmlSerializable自定义序列化或@Marc建议的DTO。 如果是DataContractSerializer您还可以使用IDataContractSurrogate 。 XmlSerializer非常高级的方案是重写XML序列化 。 也可以让T4模板为您生成属性,但这是非常先进的技术,因为它需要 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)