这个字段长度,我设置最大了 ,本机环境运行正常。算了 还是把sql语句贴出来吧 public static Article AddArticle(Article article) { string sql = "INSERT Articles (AuthorId, aTitle, aContent, aTime,aIPAddress,aImage,aClicks,aRatify,aType,aSign)" + "VALUES (@AuthorId, @aTitle, @aContent,@aTime,@aIPAddress,@aImage,@aClicks,@aRatify,@aType,@aSign)"; sql += " ; SELECT @@IDENTITY"; SqlParameter[] para = new SqlParameter[] { new SqlParameter("@AuthorId", article.Author.Id), //FK new SqlParameter("@aTitle", article.ATitle), new SqlParameter("@aContent", article.AContent), new SqlParameter("@aTime",article.ATime), new SqlParameter("@aIPAddress",article.AIPAddress), new SqlParameter("@aImage",article.AImage), new SqlParameter("@aClicks", article.AClicks), new SqlParameter("@aRatify", article.ARatify), new SqlParameter("@aType",article.AType), new SqlParameter("@aSign",article.ASign) }; int newId = DBHelper.GetScalar(sql, para); return GetArticleById(newId); }
{
Models.Article article = new Models.Article();
article.ATitle = this.txtTitle.Text.ToString();
article.AContent = txtContent.Value;
article.ATime = DateTime.Now;
article.AIPAddress = Request.UserHostAddress;
article.AImage = "";
article.AClicks = 0;
article.ARatify = 1;
article.AType = this.ddlType.SelectedIndex;
article.ASign = this.ddlSign.SelectedIndex;
article.Author = user; if (ArticleManager.AddArticle(article) != null)
{
Response.Redirect("~/refresh.aspx?msg=" + "恭喜你,发表成功!文章正在审核,请稍等。");
}
else
{
this.lblMsg.Text = "很遗憾,发表失败,请重新尝试!";
}
} 获取本地时间啊
请把你的查询语句 贴出来 这个返回的是第一列第一行的数据 是int行的么 或者能不能转换成int
请把你的查询语句 贴出来 这个返回的是第一列第一行的数据 是int行的么 或者能不能转换成int 不明白,这是是进行添加功能的。
不明白,这是是进行添加功能的。
添加用executeScalar 干嘛 这是查询用的 返回第一行第一列的值
不明白,这是是进行添加功能的。
添加用executeScalar 干嘛 这是查询用的 返回第一行第一列的值
照你这么说我放服务器上就要出错, 为嘛本机运行正常。
你查询的方法换一下这个可以取到值。
换一个executeScalar 换为ExecuteNonQuery
这个字段长度,我设置最大了 ,本机环境运行正常。算了 还是把sql语句贴出来吧
这个字段长度,我设置最大了 ,本机环境运行正常。算了 还是把sql语句贴出来吧
public static Article AddArticle(Article article)
{
string sql =
"INSERT Articles (AuthorId, aTitle, aContent, aTime,aIPAddress,aImage,aClicks,aRatify,aType,aSign)" +
"VALUES (@AuthorId, @aTitle, @aContent,@aTime,@aIPAddress,@aImage,@aClicks,@aRatify,@aType,@aSign)";
sql += " ; SELECT @@IDENTITY"; SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@AuthorId", article.Author.Id), //FK
new SqlParameter("@aTitle", article.ATitle),
new SqlParameter("@aContent", article.AContent),
new SqlParameter("@aTime",article.ATime),
new SqlParameter("@aIPAddress",article.AIPAddress),
new SqlParameter("@aImage",article.AImage),
new SqlParameter("@aClicks", article.AClicks),
new SqlParameter("@aRatify", article.ARatify),
new SqlParameter("@aType",article.AType),
new SqlParameter("@aSign",article.ASign)
}; int newId = DBHelper.GetScalar(sql, para);
return GetArticleById(newId);
}
四位ip 3*4=12 再加上点"."
你说超不