public static void ModifyArticle(Article article)
{
string sql = @"UPDATE Article SET userid =:userid,
articleTypeid =:articleTypeid,title = :title,
content =:content,times =to_date(:times,'yyyy-mm-dd'),click =:click,isIssue =:isIssue,
issueTime =to_date(:issueTime,'yyyy-mm-dd'),ImagePath=:ImagePath,FilePath=:FilePath,
isIssuePUC=to_date(:isIssuePUC,'yyyy-mm-dd'),issuePUCTime=:issuePUCTime WHERE Id =:id;";
try
{
OracleParameter[] para = new OracleParameter[]
{
new OracleParameter(":Id", article.Id),
new OracleParameter(":userid", article.User.Id),
new OracleParameter(":articleTypeid", article.ArticleType.Id), //FK
new OracleParameter(":title", article.Title),
new OracleParameter(":content", article.Content),
new OracleParameter(":times",OracleDateTime.Parse(article.Time)),
new OracleParameter(":click", article.Click),
new OracleParameter(":isIssue", article.IsIssue),
new OracleParameter(":issueTime",getDateTime(article.IssueTime)),
new OracleParameter(":ImagePath",article.ImagePath),
new OracleParameter(":FilePath",article.FilePath),
new OracleParameter(":isIssuePUC",article.IsIssuePUC),
new OracleParameter(":issuePUCTime",getDateTime(article.IssuePUCTime))
};
DBHelper.ExecuteCommand(sql, para);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
} }
{
string sql = @"UPDATE Article SET userid =:userid,
articleTypeid =:articleTypeid,title = :title,
content =:content,times =to_date(:times,'yyyy-mm-dd'),click =:click,isIssue =:isIssue,
issueTime =to_date(:issueTime,'yyyy-mm-dd'),ImagePath=:ImagePath,FilePath=:FilePath,
isIssuePUC=to_date(:isIssuePUC,'yyyy-mm-dd'),issuePUCTime=:issuePUCTime WHERE Id =:id;";
try
{
OracleParameter[] para = new OracleParameter[]
{
new OracleParameter(":Id", article.Id),
new OracleParameter(":userid", article.User.Id),
new OracleParameter(":articleTypeid", article.ArticleType.Id), //FK
new OracleParameter(":title", article.Title),
new OracleParameter(":content", article.Content),
new OracleParameter(":times",OracleDateTime.Parse(article.Time)),
new OracleParameter(":click", article.Click),
new OracleParameter(":isIssue", article.IsIssue),
new OracleParameter(":issueTime",getDateTime(article.IssueTime)),
new OracleParameter(":ImagePath",article.ImagePath),
new OracleParameter(":FilePath",article.FilePath),
new OracleParameter(":isIssuePUC",article.IsIssuePUC),
new OracleParameter(":issuePUCTime",getDateTime(article.IssuePUCTime))
};
DBHelper.ExecuteCommand(sql, para);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
} }
articleTypeid =:articleTypeid,title = :title,
content =:content,times =to_date(:times,'yyyy-mm-dd'),click =:click,isIssue =:isIssue,
issueTime =to_date(:issueTime,'yyyy-mm-dd'),ImagePath=:ImagePath,FilePath=:FilePath,
isIssuePUC=:isIssuePUC,issuePUCTime=to_date(:issuePUCTime,'yyyy-mm-dd') WHERE Id =:id;";
我自己写错语句。 不过改回来还是报同样的错误;
articleTypeid =:articleTypeid,title = :title,
content =:content,times =to_date(:times,'yyyy-mm-dd'),click =:click,isIssue =:isIssue,
issueTime =to_date(:issueTime,'yyyy-mm-dd'),ImagePath=:ImagePath,FilePath=:FilePath,
isIssuePUC=to_date(:isIssuePUC,'yyyy-mm-dd'),issuePUCTime=:issuePUCTime WHERE Id =:id;";
里面@是什么
insert into t values('1');OracleConnection conn = new OracleConnection("Data Source=xsjly;User Id=tpdivision;Password=division;");
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update t set cid=:cid";
cmd.Parameters.Add(new OracleParameter("cid","2"));
cmd.ExecuteNonQuery();
conn.Close();你参考一下我写的这个
1.new OracleParameter(":Id", OracleType.Number)
2.update语句前面没有“@”啊
3.就是和数据库对照下每个字段是否一一对应
4.就是看下sql语句中的标点符号 有没有中文的
{
string sql = @"UPDATE Article SET userid =:userid,
articleTypeid =:articleTypeid,title = :title,
content =:content,times =to_date(:times,'yyyy-mm-dd'),click =:click,isIssue =:isIssue,
issueTime =to_date(:issueTime,'yyyy-mm-dd'),ImagePath=:ImagePath,FilePath=:FilePath,
isIssuePUC=to_date(:isIssuePUC,'yyyy-mm-dd'),issuePUCTime=:issuePUCTime WHERE Id =:id;";
try
{
OracleParameter[] para = new OracleParameter[]
{
new OracleParameter(":Id", article.Id),
new OracleParameter(":userid", article.User.Id),
new OracleParameter(":articleTypeid", article.ArticleType.Id), //FK
new OracleParameter(":title", article.Title),
new OracleParameter(":content", article.Content),
new OracleParameter(":times",OracleDateTime.Parse(article.Time)),
new OracleParameter(":click", article.Click),
new OracleParameter(":isIssue", article.IsIssue),
new OracleParameter(":issueTime",getDateTime(article.IssueTime)),
new OracleParameter(":ImagePath",article.ImagePath),
new OracleParameter(":FilePath",article.FilePath),
new OracleParameter(":isIssuePUC",article.IsIssuePUC),
new OracleParameter(":issuePUCTime",getDateTime(article.IssuePUCTime))
};
DBHelper.ExecuteCommand(sql, para);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
} }
好几个地方有问题。
第一处是参数数据类型为时间时,就不需要对数据进行转换了。
第二处是末尾多了分号。
第三处参数名称里面不需要用冒号。你这里每一个都用到了。
增加参数时最好能够注明参数的数据类型。
建议:
cmd.parameters.add("name",oracletype.datetime).value = now;