How to fill Dataset with multiple tables?

前端 未结 8 662
小鲜肉
小鲜肉 2020-11-29 07:20

I\'m trying to fill DataSet which contains 2 tables with one to many relationship. I\'m using DataReader to achieve this :

    public DataSet SelectOne(int i         


        
8条回答
  •  抹茶落季
    2020-11-29 08:00

    public DataSet GetDataSet()
        {
            try
            {
                DataSet dsReturn = new DataSet();
                using (SqlConnection myConnection = new SqlConnection(Core.con))
                {
                    string query = "select * from table1;  select* from table2";
                    SqlCommand cmd = new SqlCommand(query, myConnection);
                    myConnection.Open();
                    SqlDataReader reader = cmd.ExecuteReader();
                    dsReturn.Load(reader, LoadOption.PreserveChanges, new string[] { "tableOne", "tableTwo" });
                    return dsReturn;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    

提交回复
热议问题