日期:2014-05-19  浏览次数:20691 次

问一个Access数据类型与C#对应的问题
程序示例如下:假设已有连接对象   conn
string   commStr   =   "update   temp   set   tempDate   =   @date   where   tid   =   1 "   //SQL命令
其中tempDate为Access中的日期/时间类型,常规日期格式
                        OleDbCommand   comm   =   new   OleDbCommand(commStr,conn);                           comm.Parameters.Add( "@date ",   OleDbType.DBTimeStamp).Value   =   DateTime.Now;
                        try
                        {
                                conn.Open();         //打开数据库连接                                
                                comm.ExecuteNonQuery();  
                        }
                        catch   (OleDbException   ex)
                        {
                                Console.WriteLine(ex.Message);
                        }
                        finally
                        {
                                conn.Close();       //关闭数据库连接
                        }
总是出现数据类型不匹配的异常.不知道Access的日期/时间的常规日期格式应该对应C#   OleDbType中的什么类型.问题是,我想存储带有日期小时分秒的日期格式.
请问我该怎么办?
还有,Access中的备注类型是什么?能存储多大内容?对应C#中的何种类型?
请高手指教!不胜感激!

------解决方案--------------------
sorry 刚才回答的很不正确
由于自己机器上的代码有调用 没有仔细看拼装sql的部分

经测试发现的确如lz所言

程序该为如下即可

DateTime date = DateTime.Now;

sqlstr = "update [temp] set [tempDate] = # "+date+ "# where tid = 1 ";