注册 登录
编程论坛 ASP.NET技术论坛

请问一下,SqlDataReader要怎么样转换成DataSet或DataView的数据类型

史前大暴龙 发布于 2007-03-24 09:18, 1723 次点击
请问一下,SqlDataReader要怎么样转换成DataSet或DataView的数据类型,因为数据库里的操作语句,全做成存储过程了,又不知怎么样在SqlDataAdapter中使用存储过程,哪位大哥知道的就请说一下.十分感谢!!
9 回复
#2
卡洛2007-03-24 09:56
用datatable应该可以。。
#3
IPV62007-03-24 21:44
不太清楚你的问题的意思。下面的代码参考一下吧
SqlConnection con=DB.createCon();
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=new SqlCommand("Select * from member",con);//实例化
DataSet ds=new DataSet();
sda.Fill(ds,"member");
this.DataList1.DataKeyField="userName";
this.DataList1.DataSource=ds.Tables["member"];
#4
史前大暴龙2007-03-26 11:44
那个我知道了要怎么样改了.下面是一个例子:

public DataSet GetList()
{
SqlConnection con = new SqlConnection(ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
DataSet ds=new DataSet ();
SqlDataAdapter sda = new SqlDataAdapter();
try
{
cmd.CommandText = "train_Tests_GetList";//存储过程的名字
cmd.CommandType = CommandType.StoredProcedure;
sda.SelectCommand = cmd;
sda.Fill(ds);
cmd.Dispose();
con.Close();
}
catch
{
ds = null;
cmd.Dispose();
con.Close();
}
return ds ;
}

不过那些类型之间谁会转换的?请告诉我一下.谢谢了.

[此贴子已经被作者于2007-3-26 11:53:26编辑过]

#5
Kendy1234562007-03-26 11:55
你说的这几个东西的核心都是data table。
所以没必要转换
#6
史前大暴龙2007-03-26 12:19

因为之前遇到这种要转换的问题,之前我是用了个SqlDataReader,但是要求返回的东西要DataView或是DataView,我后来就改用了上面发的那个函数,现在,我想知道一下的就是,要是我不改函数,在里面要是能转换一下的话,就简单多了,但是不知要怎么样转,就上来问一下了.呵呵

#7
卡洛2007-03-26 12:20

真要转换的话。你就把数据团都读到table里吧``然后把table附到dataset 或 dataview里

#8
史前大暴龙2007-03-26 13:40

楼上说的也行,现在又有个问题想问一下,用SqlDataAdapter时,怎么样把数据读进DataView中??

#9
卡洛2007-03-26 14:23
自己想想看吧。给点提示你。创建一个table实例然后add进去。
#10
史前大暴龙2007-03-26 22:18
DataView dv=new DataView(ds);   ds为一个数据集
1