标题:如何调用不同类的临时数据
取消只看楼主
li492986029
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-3-10
结帖率:0
已结贴  问题点数:20 回复次数:0 
如何调用不同类的临时数据

我想把数据全部放到临时数据库类里面,别的类也可以使用这个类里面的临时数据库。系统提示我“可访问性不一致”,
//临时数据库
class TransitDepot
    {
        DataSet ds = new DataSet();
        SqlDataAdapter da = null;
        DBHelper dbh = new DBHelper();
        public static string sqlSinger = "";
        public static string sqlSong = "";
        public void SingerDepot()
        {
            da = new SqlDataAdapter(sqlSinger,dbh.Connection);
            da.Fill(ds, "SingerDepot");
        }
        public void SongDepot()
        {
            da = new SqlDataAdapter(sqlSong, dbh.Connection);
            da.Fill(ds, "SongDepot");
        }
    }
//在别的类里面把数据放在临时数据库类里面
 public partial class FrmMain : Form
    {
        DBHelper dbh = new DBHelper();
        StringBuilder sql = null;
        DataSet ds = new DataSet();
        SqlDataAdapter da = null;
        private void FrmMain_Load(object sender, EventArgs e)
        {
            
            AddTransitDepot();

        }
        //添加歌手数据和歌曲数据到临时仓库
        public void AddTransitDepot()
        {
            //查询歌手信息到仓库
            sql = new StringBuilder("Select");
            sql.AppendLine("      *");
            sql.AppendLine("From");
            sql.AppendLine("      [Singer_info]");
            TransitDepot.sqlSinger = sql.ToString();

            //查询歌曲信息到仓库
            sql = new StringBuilder("Select");
            sql.AppendLine("      *");
            sql.AppendLine("From");
            sql.AppendLine("      [Song_info]");
            TransitDepot.sqlSong = sql.ToString();
        }
     }
//在别的类调用
    public partial class FrmOrderBySinger : Form
    {
        public FrmOrderBySinger()
        {
            InitializeComponent();
        }
        DataSet ds = new DataSet();
        public static FrmMain fm = new FrmMain();
        public static FrmOrderBySinger FB = new FrmOrderBySinger();
        public static TransitDepot td = new TransitDepot();
        public void Into()
        {
            MessageBox.Show(ds.Tables["SingerDepot"].Columns.ToString());
        }
    }
搜索更多相关主题的帖子: 数据库 数据 public null 如何 
2012-03-10 03:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-362704-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050627 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved