开发者

how to return dataset in c#.net

This is my class code. I want to return the dataset from the开发者_StackOverflow社区 procedure _return() I want to return this to another form where I called the procedure. What return type should I use? How to implement it?

public class Class1
{
    SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS2005;AttachDbFilename='C:\Users\krish\Documents\Visual Studio 2005\WebSites\TRS\App_Data\Database.mdf';Integrated Security=True;User Instance=True");
    SqlCommand cmd = new SqlCommand();
    SqlDataAdapter da = new SqlDataAdapter();
    DataSet ds = new DataSet();

    public void _return(String qry)
    {
        con.Open();
        da = new SqlDataAdapter(qry, con);
        da.Fill(ds, "details");
        con.Close();
    }
}


You can mention function return type DataSet and simply return that DataSet

public DataSet _return(String qry)
{
    con.Open();
    da = new SqlDataAdapter(qry, con);
    da.Fill(ds, "details");
    con.Close();
    return ds;

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜