C#中,请问如何将当前的时间入到Access数据库中? ( 积分: 5 )

  • 主题发起人 mycwcgr_new
  • 开始时间
M

mycwcgr_new

Unregistered / Unconfirmed
GUEST, unregistred user!
C#中,请问如何将当前的时间入到Access数据库中?
C#中,请问如何将当前的时间入到Access数据库中?
我不知道在C#中,如何使用SQL语句Insert,将当前时间插入到时间字段中
是不是要用这种表示法 Insert into table (DateTimeField) values ('#1/1/2005#');
即将当前的时间转化为类似于'#1/1/2005#'的形式后执行Insert语句
但是上面的方法比较麻烦,而Delphi中,因为TDateTime事件上是一个浮点数,在数据库中存贮的也是一个浮点数
所以在Delphi中,可以用Insert into table (DateTimeField) values (198789.234);
表示,(注:假定198789.234是当前时间的浮点数)
不知在C#中,有没有好的方法,我非常不喜欢将时间值转化为字符串进行操作,一则不方便,二则在国际化时容易出错
 
C#中,请问如何将当前的时间入到Access数据库中?
C#中,请问如何将当前的时间入到Access数据库中?
我不知道在C#中,如何使用SQL语句Insert,将当前时间插入到时间字段中
是不是要用这种表示法 Insert into table (DateTimeField) values ('#1/1/2005#');
即将当前的时间转化为类似于'#1/1/2005#'的形式后执行Insert语句
但是上面的方法比较麻烦,而Delphi中,因为TDateTime事件上是一个浮点数,在数据库中存贮的也是一个浮点数
所以在Delphi中,可以用Insert into table (DateTimeField) values (198789.234);
表示,(注:假定198789.234是当前时间的浮点数)
不知在C#中,有没有好的方法,我非常不喜欢将时间值转化为字符串进行操作,一则不方便,二则在国际化时容易出错
 
如果插入当前时间:Insert into table (DateTimeField) values ( DateTime.Today);
如果是时间字符串:Insert into table (DateTimeField) values ( DateTime.Parse(.'2005-4-9'));
 
用参数吧
command.CommandText = "insert into Region (RegionID, RegionDescription)
values (@id, @desc)";
//SQL Server 7.0 throws an exception here.
//Comment the following line to resolve this problem against SQL Server 7.0.
command.Prepare();
command.Parameters.Add("@id", SqlDbType.Int,4);
command.Parameters.Add("@desc", SqlDbType.Char,50);
 
顶部