test表中,有 id , name 字段。id   name 1    aa
2    vv
3    dd
6    ss
9    66
1. 我怎么查询,能出来这样:xx   id  name 1    1    aa
2    2    vv
3    3    dd
4    6    ss
5    9    662. 我select * from test后,怎么把id和name放进数组,并怎么在后台读取。3. 变量能循环定义吗?比如我string s1=xx ; string s2 =xx; string s3=xx;
   能不能写个for循环什么的来定义?

解决方案 »

  1.   

    3. 用数组吧:string[] s = new string[3];
    for (int i = 0; i < s.Length; i++)
      s[i] = "xx";
      

  2.   

    1. rownum
    2. Reader 循环, 
    3, 用数组或者Arraylist啊。
      

  3.   

    select row_number() over(order by id) as xx,* from test
      

  4.   

    你写select 语句的时候使用case when 试试
      

  5.   

    select ROW_NUMBER() OVER(order by cardid),* from  MemberCard
      

  6.   

    select ROW_NUMBER() OVER(order by id),* from test
      

  7.   

    2.把结果放进datatable,然后读取第2,3列
      

  8.   


    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex != -1)
            {
                int id = e.Row.RowIndex + 1;
                e.Row.Cells[0].Text = id.ToString();
            }
        }
      

  9.   

    'ROW_NUMBER' 不是可以识别的 函数名。第一  第二 还没有解决。。第三解决了,感谢wuyi8808。第二我不想用datatable,想学习一下数组,谢谢谢谢分不多,只给正确的,谢谢谢谢
      

  10.   


    LZ 的数据库是什么:Microsoft SQL Server 2000、2005 或者其他?
      

  11.   


    如果是 Microsoft SQL Server 2005,5楼的答案就是正确的。
      

  12.   

    (1)一种是从数据库中就给添加了
    select row_number() over(order by CustomerID) from Customers
    (2)gridview中可以是用container.dataitemindex,Reapter控件中可以用container.itemindex
      

  13.   

    这个得看你的数据库版本了...
    select ROW_NUMBER() OVER(order by id),* from test
    在SQL2005 ,oracle中是可行的
    但是SQL Server 2000中是没有这个函数的,那除了迁移数据库版本外,有没有替代的解决方法呢?答案是肯定的。
    有两个思路
    1、使用临时表。
    如果是在存储过程中,这是一个不错的选择。
    创建一个临时表,其中除了需要的查询结果外,还一个记数列。查询结果放入临时表后(一般情况下可直接使用Insert into语句),用代码进行记数,更新记数列的值。
    在记数列数值的生成方法上,还有一个改进的办法是直接将该列定义为自增长字段。这样“记数”的代码也省掉了。2、采用自连接。
    如果是在代码中,不便于使用临时表,可以采用此方法。比如执行一个查询统计,需要一个替代的SQL语句。
    这个方法实际上是通过表的自连接给结果行“分等级”的思路来实现的。
    语句如下:
    select count(*),e1.ENo, e1.EName
    from Employee e1
    inner join Employee e2 on e1.ENo >= e2.ENo
    group by e1.ENo, e1.EName
    order by 1  或者把join条件放到where子句中:
    select count(*),e1.ENo, e1.EName
    from Employee e1, Employee e2,
    where e1.ENo >= e2.ENo
    group by e1.ENo, e1.EName
    order by 1如果ENo字段值不重复,还可以这样写:
    select (select count(*) from Employee e2 where e1.ENo >= e2.ENo), e1.ENo, e1.EName
    from Employee e1
    order by 1如果ENo字段值有重复的情况,要使用最后一种写法可以将where条件变通一下,如:
    where e1.ENo+e1.EName >= e2.ENo+e2.EName
    总能找到不存在重复值的表达式的。
      

  14.   

    嗯  建个临时表 declare @temp table
    (
    indexid int identity(1,1),
    empno int
    ) set rowcount @upperbound
    insert into @temp(empno)
    select adminId from adminInfo select * from adminInfo a, @temp b
    where adminId = b.empno
    and b.indexid > @lowerbound 
    and b.indexid < @upperbound