执行sql语句时,有时候类型转换很麻烦,用参数方式能解决,UPDATE命令一样用参数
下面是用参和不用参混合使用,updateTime是用参数方式更新.
string SqlCmd = "UPDATE BookIndex SET chapterTotal = " + chapterID.ToString()
+ ",updateTime = @updateTime" //使用参数
+ " FROM BookIndex WHERE bookID = " + bookID;
SqlCommand CmdObj = new SqlCommand(SqlCmd, (SqlConnection)(page.Application["Con"]));
CmdObj.Parameters.Add("@updateTime", SqlDbType.DateTime).Value = System.DateTime.Now;//给参数赋值