DECLARE ItemBom_cursor CURSOR FOR SELECT FitemID FROM table1 group by FitemID Open ItemBom_cursor Fetch Next From ItemBom_cursor into @id while @@Fetch_status=0 begin insert into t_warehouseStock(FitemID,FBatchNo,FBomInterID,ICinvQty,InQty,OutQty,PlinQty) exec sp @ID Fetch Next From ItemBom_cursor into @FitemID,@FBomInterID end Close ItemBom_cursor DEALLOCATE ItemBom_cursor /***********************************************************************************/
当我用 SqlCommand comm = new SqlCommand(); comm.CommandType = CommandType.StoredProcedure; comm.Connection = myConn; comm.CommandText = "sp1"; comm.ExecuteReader(); 或 SqlCommand comm = new SqlCommand(); comm.Connection = myConn; comm.CommandText = "exec sp1"; comm.ExecuteNonQuery(); 获得的结果,都是sp1执行到“…… delete from t_warehouseStock ”的结果,后面的游标没有执行 但该存储过程在数据库的查询里直接调用,是正常的,游标部分也被正常执行了