DataGrid的问题

ballnan 2005-04-19 07:04:11

id name
1 b
1 c
我要把表里字段name里的内容显示在DataGrid里面的同一记录的同一列里面
也就是说b和c放在DataGrid的同一格里面
请问怎样实现?说具体点谢谢
...全文
189 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
nga96 2005-04-21
  • 打赏
  • 举报
回复
sql
ballnan 2005-04-20
  • 打赏
  • 举报
回复
用存储过程??怎么写啊???
各位大哥详细点吧!!!!
ballnan 2005-04-20
  • 打赏
  • 举报
回复
用SQL语句怎样写啊???说具体点行吗
haonanernet 2005-04-20
  • 打赏
  • 举报
回复
看看这个列子吧,能够通过datagrid直接调入数据了
这也是SQL版块  xluzhong(Ralph)的回答,我测试了下,完全正确
zjcxc好象不行


-------------参考例子
--建立测试环境
create table tb2 (id int,type nvarchar(10))
insert into tb2 select 1,'a'
insert into tb2 select 1,'b'
insert into tb2 select 1,'c'
insert into tb2 select 1,'d'
insert into tb2 select 2,'a'
insert into tb2 select 3,'b'
insert into tb2 select 4,'c'
insert into tb2 select 4,'d'
go
--查询处理
create function f_catString(@id int)
returns nvarchar(1000)
as
begin
declare @s nvarchar(1000)
set @s=''
select @s=@s+','+type from tb2 where id=@id
return(stuff(@s,1,1,''))
end
go
--调用函数
select id,dbo.f_catString(id) as type from tb2 group by id
go

--删除测试环境
Drop Table tb2
hamadou 2005-04-20
  • 打赏
  • 举报
回复
好象直接用sql语句写不容易,用存储过程写就是了。很简单的!
zhendeqiufeng 2005-04-20
  • 打赏
  • 举报
回复
select id + name from 表
hamadou 2005-04-20
  • 打赏
  • 举报
回复
CREATE PROCEDURE union_name
AS
declare @s varchar,@id as int,@name varchar ,@temp varchar,@t_id int
set @temp=""
set @t_id=0
create table #temp(id int not null primary key,name varchar(20) not null )
declare my_cusor cursor for select id,name from u_name order by id
open my_cusor
fetch next from my_cusor
into @id, @name
while @@FETCH_STATUS = 0
begin
if @id <>@t_id
begin
insert into #temp(id,name) values(@id,@name)
set @t_id = @id
end
else
begin
update #temp set name = name + @name where id=@t_id
end
fetch next from my_cusor
into @id, @name
end
close my_cusor
deallocate my_cusor
select * from #temp
GO
gyf19 2005-04-19
  • 打赏
  • 举报
回复
这种表现用DataGrid本身是没法实现的了。
解决办法:
1。把你要帮定的DataTable重新处理为你想要的样子,具体办法就是遍列啦
或者
2。直接用SQL语句得到你想要的数据
jcdwin3 2005-04-19
  • 打赏
  • 举报
回复
转sql版吧,估计用子查询
chenczx1 2005-04-19
  • 打赏
  • 举报
回复
帮你UP
LoveCherry 2005-04-19
  • 打赏
  • 举报
回复
http://www.cnblogs.com/zhongru_tu/archive/2005/01/27/98302.html
v192 2005-04-19
  • 打赏
  • 举报
回复
这种表现用DataGrid本身是没法实现的了。解决办法,把你要帮定的DataTable重新处理为你想要的样子,具体办法就是遍列啦

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧