从数据库表中检索日期并将其分配给vb中的变量 [英] Retrieve date from database table and assign it to a variable in vb

查看:175
本文介绍了从数据库表中检索日期并将其分配给vb中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从数据库表中检索最后一条记录的日期值并将其分配给vb中的变量?我的表使用SQL Server作为数据库,其中包含"fact1/fact2/fact3/total/date/timestamp"之类的列..

how can i Retrieve date value of last record from a database table and assign it to a variable in vb?? My table has columns like "fact1/fact2/fact3/total/date/timestamp" i''m using sql server as my database..

推荐答案

dim ds as新数据集
将字符串dim qry作为字符串=从tabletemp中选择*"
将dim命令作为sqlcommand =新的sqlcommand(qry,connection)
dim da as sqldataadapter = new sqldataadapter)命令)
da.fill(ds,"tabletemp")

暗淡的datevariables作为字符串

datevariable = ds.tables(0).rows(ds.tables(0).rows.count-1).item("date").tostring



''''''''这是您从保存的最后一条记录中获取日期值的方式
dim ds as new dataset
dim qry as string = "select * from tabletemp"
dim command as sqlcommand = new sqlcommand(qry,connection)
dim da as sqldataadapter = new sqldataadapter)command)
da.fill(ds,"tabletemp")

dim datevariable as string

datevariable = ds.tables(0).rows(ds.tables(0).rows.count - 1).item("date").tostring



'''''''' this is how u will get the value of date from last record u saved


请参见下面的代码
see, below code
dim datevar = dbScalarvalue("select date from tbl where timstampcol=max(timestampcol)")
'dbScalarvalue function take query and give result from sql, database connection and all that will manage internally by function.


祝您编码愉快!
:)


Happy Coding!
:)


您还可以通过查询转换日期
sql ="select *,Convert(char(10),date),103)作为来自tabletemp的日期"
这将为您提供"dmy"格式的日期
You can also convert date by query
sql="select *,Convert(char(10),date),103)As date from tabletemp"
this will give u date in ''dmy'' format


这篇关于从数据库表中检索日期并将其分配给vb中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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