StringBuilder strSql = new StringBuilder();
strSql.Append("insert into Photo(");
strSql.Append("FocusImg)");
strSql.Append(" values (");
strSql.Append("@FocusImg)");
strSql.Append(";set @ReturnValue= @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@FocusImg", SqlDbType.NVarChar,250),
new SqlParameter("@ReturnValue",SqlDbType.Int,4)
};
parameters[0].Value = model.FocusImg;
parameters[1].Direction = ParameterDirection.Output;
List<CommandInfo> sqllist = new List<CommandInfo>();
CommandInfo cmd = new CommandInfo(strSql.ToString(), parameters);
sqllist.Add(cmd); if (model.PhotoAlbumS != null)
{
StringBuilder strSql2;
foreach (Model.PhotoAlbum models in model.PhotoAlbumS)
{
strSql2 = new StringBuilder(); strSql2.Append("insert into PhotoAlbum(");
strSql2.Append("PhotoID,BigImg)");
strSql2.Append(" values (");
strSql2.Append("@PhotoID,@BigImg)");
SqlParameter[] parameters2 = {
new SqlParameter("@PhotoID", SqlDbType.Int,4),
new SqlParameter("@BigImg", SqlDbType.NVarChar,255)};
parameters2[0].Value = ParameterDirection.InputOutput;
parameters2[1].Value = models.BigImg;
cmd = new CommandInfo(strSql2.ToString(), parameters2);
sqllist.Add(cmd);
}
} DbHelperSQL.ExecuteSqlTranWithIndentity(sqllist);
return (int)parameters[1].Value;return (int)parameters[1].Value; 这句都能正确返回刚添加的ID,而插入到PhotoAlbum表中的PhotoID字段值一直为3,并不会写入最新的Photo表ID值,这是什么原因
谢谢
解决方案 »
- 后台怎么获取这个 订单编号 ID的值
- 新闻内容页跟新闻列表页应该怎么做?(c#)
- 自定义公式怎么做啊 高手给指点个思路!
- 在datagrid中,我想单击某个单元格让它跳到相应的页面,怎么做?给分!!
- Web的Button控键,如何实现disable,但是表示的字不变暗?
- 紧急求救!!!!在框架中,top.aspx,left.aspx,right.aspx,三个页面,right.aspx经常出现上下和左右的滚动条,影响美观,同时对客户操作
- xml问题
- 网站延迟严重,帮忙看下是什么原因~~
- 新手的问题
- 一个用asp.net by vb 做登陆页的问题!!求助!!急急!
- 求助webservice x相关
- 不能在 Page 回调中调用 Response.Redirect。
改成
parameters2[0].Direction= ParameterDirection.InputOutput;
感谢xiaozhihui5535