从数据库中检索存储的日期和时间

编程入门 行业动态 更新时间:2024-10-22 14:37:18
本文介绍了从数据库中检索存储的日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

您的问题太含糊了.这完全取决于哪种数据库以及如何设置数据库.您甚至都没有告诉过我们是否要从Windows窗体项目或Web项目访问它. 听起来您需要做一些研究.尝试 google [ ^ ]基础教程.或者,您可以阅读某些文章 [ ^ ] 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 = " SelectDateTime" cmd.CommandType = CommandType.StoredProcedure cmd.Connection = sqlConnection1 cmd.Parameters.Add(新建 SqlParameter(" @ FileName ",文件名)) cmd.Parameters.Add(新建 SqlParameter(" @ FilePath ",filePath)) 尝试 sqlConnection1.Open reader = cmd.ExecuteReader 捕获,例如 As 异常 最后 sqlConnection1.Close 结束 尝试

其他解决方案之一是使用ADO.Net实体框架. 看这些 msdn.microsoft/en-us/data/ee712907 [ ^ ] msdn.microsoft/en-us/data/aa937723 [ ^ ]

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

解决方案

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 msdn.microsoft/en-us/data/ee712907[^] msdn.microsoft/en-us/data/aa937723[^]

更多推荐

从数据库中检索存储的日期和时间

本文发布于:2023-11-28 16:31:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643140.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   日期   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!