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循环什么的来定义?
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循环什么的来定义?
for (int i = 0; i < s.Length; i++)
s[i] = "xx";
2. Reader 循环,
3, 用数组或者Arraylist啊。
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();
}
}
LZ 的数据库是什么:Microsoft SQL Server 2000、2005 或者其他?
如果是 Microsoft SQL Server 2005,5楼的答案就是正确的。
select row_number() over(order by CustomerID) from Customers
(2)gridview中可以是用container.dataitemindex,Reapter控件中可以用container.itemindex
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
总能找到不存在重复值的表达式的。
(
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