用dataset返回值问题
代码是这样的
default2.aspx代码
id = Request.QueryString["id"].ToString();
DAL.DisciplineInfo da = new DAL.DisciplineInfo();
DataSet ds = da.GetAll(id, "selectid");
Name = ds.Tables[0].Rows[0][1].ToString();
Type = ds.Tables[0].Rows[0][2].ToString();
Grade = ds.Tables[0].Rows[0][3].ToString();
ContructGrade =Convert.ToByte(ds.Tables[0].Rows[0][4].ToString());
Field = ds.Tables[0].Rows[0][5].ToString();
LeaderNO = ds.Tables[0].Rows[0][6].ToString();
Intro = ds.Tables[0].Rows[0][7].ToString();
DisciplineInfo.cs 代码
public DataSet GetAll(string id,string zx)
{
SqlParameter[] para ={
new SqlParameter("@zx",zx),
new SqlParameter("@Id",id),
};
return SqlHelper.GetList("DisciplineInfo1", para);
SqlHelper.cs代码
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = BuildCommand(storeProcName, para);
DataSet ds = new DataSet();
sda.Fill(ds);
Closecon();
return ds;
存储过程是
ALTER proc [dbo].[DisciplineInfo1] @zx varchar(6),@id varchar(6)=null,@DisciplineName varchar(40)=null,@DisciplineType char(6)=null,@DisciplineGrade char(8)=null,@ContructGrade tinyint=null,@ToDisciplineField varchar(10)=null,@AcademicLeaderNO varchar(8)=null,@DisciplineIntro text=null
as
if @zx='insert'
insert DisciplineInfo values(@id,@DisciplineName,@DisciplineType,@DisciplineGrade,@ContructGrade,@ToDisciplineField,@AcademicLeaderNO,@DisciplineIntro);
if @zx='update'
update DisciplineInfo set
DisciplineName=@DisciplineName,DisciplineType=@DisciplineType,DisciplineGrade=@DisciplineGrade,ContructGrade=@ContructGrade,ToDisciplineField=@ToDisciplineField,AcademicLeaderNO=@AcademicLeaderNO,DisciplineIntro=@DisciplineIntro
where Id=@id;
if @zx='delete'
DELETE FROM DisciplineInfo WHERE Id=@id;
if @zx='select'
select * from DisciplineInfo;
if @zx='selectid'
select * from DisciplineInfo where Id=@id;
为什么总是返回首行首列的,不能返回指定编号的数据啊
[解决办法]
那取决于你的id值是多少,你看看id值变没变,从id入手查问题
[解决办法]
在datalist中使用模板列,通过ID查询值
或使用model,使用实体类为属性,显示NAME