一般有返回值的函数是  int dataset(),  一般是用int  string  做为开头,有用DataSet做为开头吗?  我没有学好,DataSet是一个类呀?

解决方案 »

  1.   

    public DataSet GetData()
    {}
      

  2.   

    DataSet 你可以看成一种复杂的数据结构,所以当然能作为一个函数的返回值。
    可以直接赋给一个数据绑定控件的数据源。例如:    /// <summary>
        /// Returns a DataSet which contains all database stored images
        /// </summary>
        /// <returns>A DataSet which contains all database stored images
        /// images</returns>
        public static DataSet GetImages()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("SELECT ID, PIC");
            sb.Append(" FROM TESTPIC");        //use the web.config to store the connection string, using statement ensure connection always closes
            using (OracleConnection connection = new OracleConnection(ConfigurationManager.ConnectionStrings["EasyThumbs_DB"].ConnectionString))
            {
                try
                {
                    OracleCommand command = new OracleCommand(sb.ToString(), connection);
                    command.CommandType = CommandType.Text;;
                    //execute stored procedure and return DataSet                OracleDataAdapter da = new OracleDataAdapter();
                    da.SelectCommand = command;
                    DataSet ds = new DataSet();
                    da.Fill(ds, "PIC");
                    return ds;
                }
                catch (OracleException ex)
                {
                    throw new Exception(ex.Message, ex);
                }
            }
        }