从数据库中检索存储的日期和时间 [英] Retrive stored date and time from database

查看:89
本文介绍了从数据库中检索存储的日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经将文件创建日期和时间存储到数据库中.现在如何从vb.net中的数据库中检索它?有太多可用的信息,很难相信至少在研究上付出了一定努力的任何人都没有盲目地发现任何东西.


您的问题太含糊了.这完全取决于哪种数据库以及如何设置数据库.您甚至都没有告诉过我们是否要从Windows窗体项目或Web项目访问它.

听起来您需要做一些研究.尝试文章 [ ^ ] CodeProject.当您遇到更具体的问题时,请返回此处并发布您正在使用的代码以及收到的任何错误消息,我们将为您提供帮助.


您好

解决方案之一是在数据库(SQL Server)中创建存储过程.

例如:
创建

 过程 SelectDateTime
(
     @ FileName   as   NVarChar ( 128 ),
     @ FilePath   As   NVarChar ( 256 )
)
目标
开始
        选择 * 来自 MyTable
                        其中 MyTable.FileName =  @ FileName   And 
                                    MyTable.FilePath =  @ FilePath 
结束 



然后,您可以从VB.Net执行调用存储过程.


  Dim  sqlConnection1  As  SqlConnection =  New  SqlConnection(" )
 Dim  cmd  As  SqlCommand = 新建 SqlCommand
 Dim 阅读器 As  SqlDataReader
cmd.CommandText = " 
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = sqlConnection1
cmd.Parameters.Add(新建 SqlParameter(" ,文件名))
cmd.Parameters.Add(新建 SqlParameter(" ,filePath))
尝试
     sqlConnection1.Open
     reader = cmd.ExecuteReader
捕获,例如 As 异常
     
最后
     sqlConnection1.Close
结束 尝试 



其他解决方案之一是使用ADO.Net实体框架.
看这些

http://msdn.microsoft.com/en-us/data/ee712907 [ ^ ]

http://msdn.microsoft.com/en-us/data/aa937723 [ ^ ]


we have stored file creation date and time to the database. now how to retrive it from database in vb.net?

解决方案

You seriously need to at least try something before asking. There is so much information available for this it is difficult to believe anyone who has at least put some effort into research hasn''t blindly stumbled upon anything.


Your question is way too vague. It all depends on what kind of database and how your database is setup. You haven''t even told us if you are trying to access this from a windows forms project or a web project.

It sounds like you need to do some research. Try google[^] for some basic tutorials. Or you can read some of the articles[^] here on CodeProject. When you run into a more specific problem, then come back here and post the code you are working with and any error messages you get and we can help you.


Hello

One of the solution is creating a stored procedure in your database (SQL Server)

For example:
Create

Procedure   SelectDateTime
(
    @FileName   as  NVarChar(128),
    @FilePath   As  NVarChar(256)
)
As
Begin
        Select  *   From    MyTable
                        Where   MyTable.FileName = @FileName    And
                                    MyTable.FilePath =  @FilePath
End



Then you execute call your Stored Procedure from VB.Net


Dim sqlConnection1 As SqlConnection = New SqlConnection("The Connection String")
Dim cmd As SqlCommand = New SqlCommand
Dim reader As SqlDataReader
cmd.CommandText = "SelectDateTime"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = sqlConnection1
cmd.Parameters.Add(New SqlParameter("@FileName", fileName))
cmd.Parameters.Add(New SqlParameter("@FilePath", filePath))
Try 
     sqlConnection1.Open
     reader = cmd.ExecuteReader
Catch ex As Exception
     
Finally
     sqlConnection1.Close
End Try



One of the other solutions is using ADO.Net Entity Framework.
Look at these

http://msdn.microsoft.com/en-us/data/ee712907[^]

http://msdn.microsoft.com/en-us/data/aa937723[^]


这篇关于从数据库中检索存储的日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆