我如何将数据读取器转换为数据集 [英] how i can convert data reader to the data set

查看:47
本文介绍了我如何将数据读取器转换为数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将数据读取器转换为数据集



how i can convert data reader to the data set

public void GetData( )
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Mob"].ConnectionString);
            SqlCommand cmd = new SqlCommand("GetData", con);
            DataSet ds = new DataSet();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = con;
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
       

            con.Close();
       
    }

推荐答案

看看这个:



http://www.dotnetcurry.com/ShowArticle.aspx?ID=143 [< a href =http://www.dotnetcurry.com/ShowArticle.aspx?ID=143target =_ blanktitle =New Window> ^ ]



http://www.dnzone.com/forum/topic/712/ [ ^ ]
Look at this:

http://www.dotnetcurry.com/ShowArticle.aspx?ID=143[^]

http://www.dnzone.com/forum/topic/712/[^]


public DataSet GetData( )
        {
DataSet ds = new DataSet();
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Mob"].ConnectionString);
            SqlCommand cmd = new SqlCommand("GetData", con);
            DataSet ds = new DataSet();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = con;

            con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd); //You don't need a DataReader, fill the dataset instead.
da.Fill(ds);   
            con.Close();
       return ds;
    }





希望有所帮助。



Hope it helps.




此处无需使用 SqlDataReader 。使用 SqlDataAdapte

试试这个:

Hi,
No need to use SqlDataReader here. Use SqlDataAdapte.
Try this:
public void GetData( )
{
    DataSet ds = new DataSet();
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Mob"].ConnectionString);
    con.Open();
    SqlCommand cmd = new SqlCommand("GetData", con);
    cmd.CommandType = CommandType.StoredProcedure;
    SqlDataAdapter da = new SqlDataAdapte(cmd); 
    //Filling the records in dataset
    da.Fill(ds); 
    con.Close();       
}







--Amit




--Amit


这篇关于我如何将数据读取器转换为数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆