asp.net 无法更新ACCESS数据库的问题
下面这一段代码执行时,没有任何提示出错.但是就是无法更新access数据库,,使用MSSQL2005数据库却可以正常使用.
尝试了好久,发现,在使用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("@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
}
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.
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
}

浙公网安备 33010602011771号