asp.net 无法更新ACCESS数据库的问题

下面这一段代码执行时,没有任何提示出错.但是就是无法更新access数据库,,使用MSSQL2005数据库却可以正常使用.

 1        public static void UpdateNews(int id  , string title  , string content  , DateTime publishTime  , string url )
 2        {
 3            using (OleDbConnection connection = SqlDataProvider.GetOleDbConnection())
 4            {
 5                string sqlStr = " UPDATE [News] SET [Title]=@Title, [Content]=@Content, [PublishTime]=@PublishTime, [Url]=@Url WHERE ID=@ID";
 6
 7                OleDbCommand command = new OleDbCommand(sqlStr, connection);
 8
 9                command.Parameters.Add("@ID", OleDbType.Integer).Value = id;
10
11                command.Parameters.Add("@Title", OleDbType.Char).Value = title;
12    
13                command.Parameters.Add("@Content", OleDbType.VarWChar).Value = content;
14    
15                command.Parameters.Add("@PublishTime", OleDbType.DBDate).Value = publishTime;
16
17                command.Parameters.Add("@Url", OleDbType.VarWChar).Value = url;
18
19                connection.Open();
20                command.ExecuteNonQuery();
21                connection.Close();
22            }

23        }

尝试了好久,发现,在使用ACCESS时。sqlStr里的参数序列必须和下面的command里的参数序列一致才能正常更新,也就是必须把   command.Parameters.Add("@ID", OleDbType.Integer).Value = id;
剪切到17行之后。才能正常运行。
 1        public static void UpdateNews(int id  , string title  , string content  , DateTime publishTime  , string url )
 2        {
 3            using (OleDbConnection connection = SqlDataProvider.GetOleDbConnection())
 4            {
 5                string sqlStr = " UPDATE [News] SET [Title]=@Title, [Content]=@Content, [PublishTime]=@PublishTime, [Url]=@Url WHERE ID=@ID";
 6
 7                OleDbCommand command = new OleDbCommand(sqlStr, connection);
 8        
 9                command.Parameters.Add("@Title", OleDbType.Char).Value = title;
10    
11                command.Parameters.Add("@Content", OleDbType.VarWChar).Value = content;
12    
13                command.Parameters.Add("@PublishTime", OleDbType.DBDate).Value = publishTime;
14
15                command.Parameters.Add("@Url", OleDbType.VarWChar).Value = url;
16
17                command.Parameters.Add("@ID", OleDbType.Integer).Value = id;
18
19                connection.Open();
20                command.ExecuteNonQuery();
21                connection.Close();
22            }

23        }
不知道这算不算ACCESS的BUG.

posted on 2007-07-19 22:56  心凡  阅读(1256)  评论(13编辑  收藏  举报

导航