数据库中有 ID , num ,sum 三个字段 我想根据ID 查询 num 并在 lable中显示 该怎么样查询呢 各位帮帮忙

[复制链接]
查看11 | 回复5 | 2010-9-2 10:49:13 | 显示全部楼层 |阅读模式
数据库中有 ID , num ,sum 三个字段 我想根据ID 查询 num 并在 lable中显示 该怎么样查询呢 各位帮帮忙分数不多可还望各位见谅
查询语句我知道怎么写 关键是怎样在lable中显示 查询的结果 假设就一条数据信息

回复

使用道具 举报

千问 | 2010-9-2 10:49:13 | 显示全部楼层
具体方法例如: string sql = "select 姓名 from stu_info where 学号=222";
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=studenttest;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand(sql,con);
string name= cmd.ExecuteScalar().ToString();

回复

使用道具 举报

千问 | 2010-9-2 10:49:13 | 显示全部楼层
关键看你怎么接收查询到的数据的,如果你用实体接收你查询到的数据的话,那就写this.Label1.text=实体对象.num;就可以了
回复

使用道具 举报

千问 | 2010-9-2 10:49:13 | 显示全部楼层
select cast (num as varchar(5)) +'' + cast(sum as varchar(5))from 表where id=
回复

使用道具 举报

千问 | 2010-9-2 10:49:13 | 显示全部楼层
首先得到ID数据层shujuceng写好方法 Select(int id)实体层 shiticeng a=shujuceng.Select(id)显示 this.lable.text=a.num.tostring();//或者Convert.toString(a.num)
回复

使用道具 举报

千问 | 2010-9-2 10:49:13 | 显示全部楼层
select num from 表明 where ID = 变量
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行