简体   繁体   中英

how to return dataset in c#.net

This is my class code. I want to return the dataset from the 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;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM