English 中文(简体)
如何利用日期和时间变量来查询数据库?
原标题:How to make a database consult using a date and time variable?

我有以下线性代码用于从数据库中检索数据:

DataTable newEquipmentTable = database.Connection.RetrieveData(database.AdapterType, string.Format("SELECT ID FROM Equipment WHERE Name =  {0}  AND CreatedOn =  {1} ", equipment.Name, equipment.CreatedOn.ToString("yyyy-MM-dd HH:mm:ss.fff")));

它留下了一个错误,即“变形数据类型转换为日间数据类型,造成超距离值”。

当我进行直接协商时,利用以下询问,我回去了预期结果。

SELECT ID FROM Equipment WHERE Name =  aa  AND CreatedOn =  2012-04-17 19:42:49.650 

我做了什么错误?

最佳回答

请注意:datetime 类型不能在<代码>1753-01之前持有数值。

在查询数据库以发现问题之前,仅对“宝库”的铺设情况进行检查。

然而,最好的做法是使用一个参数分类的查询(如,例如);否则,你会很容易在SLjection in

问题回答

设备的价值如何。 是否建立?

我认为,在保护者或适用者的文化环境中存在问题。 这不能直接掩盖你的日期。 用户文化环境将解决问题。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...