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

Gridview 加载的列表中间插入值,操作数据库 如何插入及修改编号
表格的格式如下:
id  name   ischeck
1   jack     1
2   tony     2
3   amanda   3
4   xiao     4
5   ming     5

问题1 :我如何先根据ID的顺序,给ischeck的列插入编号呢?语句怎么写

插入如上表的编号以后,因为我表格的排序要用ischeck来排序,当我要在id为2、3 中间插入一个值 ,其实就是给ischeck 重新编号我该怎么弄,效果如下表显示

id  name   ischeck
1   jack     1
2   tony     2
3   amanda   4
4   xiao     5
5   ming     6
6   tao      3

这样的更新语句怎么写?求各位帮忙!答者给分!谢谢!

------解决方案--------------------
insert into table 
select id,name,max(id)+1
from table

CREATE Proc spprod
@Uid int, 
@name varchar(255),
@NewOrderIndex smallint
as  
 Declare @OrderIndex int    
 
 Select @OrderIndex=OrderIndex from DDASCommand where Uid=@Uid         
  if(@OrderIndex<@NewOrderIndex)        
    Begin        
    Update table set check=check-1 where check>@OrderIndex and check<=@NewOrderIndex        
    Update table set name=@name,check=@NewOrderIndex where id=@id  
    End        
  Else          
   Begin        
   Update table set check=OrderIndex+1 where check<@OrderIndex and check>=@NewOrderIndex        
   Update table set check=@NewOrderIndex,name=@name where id=@id           
 End 
------解决方案--------------------
引用:
Quote: 引用:

insert into table 
select id,name,max(id)+1
from table

CREATE Proc spprod
@Uid int, 
@name varchar(255),
@NewOrde