日期:2014-05-17  浏览次数:20526 次

事务添加返回值的问题。

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)};