using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using DB;
using System.Threading;namespace SourceReadDemo
{
    class Class1
    {
        private bool flag;//用于关闭线程
        private bool flag1;
        private Thread thread1;
        private Thread thread;//定义一个线程
        //public delegate void MyInvoke(DataSet ds);//定义一个委托
        SqlConnection con = new SqlConnection("server=.;database=pubs;uid=sa;pwd=");
        DataSet ds = null;//声明全局的dataset
        string sql = "";
        public DataSet start(string sql)“SourceReadDemo.Class1.start(string):并非所有的代码路径都返回值         {
            this.sql = sql;
            
            //启动线程
            flag = true;
            flag1 = true;
            thread = new Thread(new ThreadStart(threadProc));
            thread1 = new Thread(new ThreadStart(threa1));
            thread.Start();
            thread1.Start();
            thread.Priority = ThreadPriority.Highest;//将读数据线程优先
            
        }
        ////线程回调函数
       private void threadProc()
        {
            while (flag)
            {                DataBind();
                Thread.Sleep(100);
            }
        }
        private void threa1()
        {
            while (flag1)
            {
                qu();
                Thread.Sleep(1000);
            }        }
        public DataSet DataBind()
        {
            DataSet dss = new DataSet();
            try
            {
                if (sql != "")
                {
                    SqlDataAdapter sdat = new SqlDataAdapter(sql, con);
                    sdat.Fill(dss, "student");
                    
                }
                {                }
                
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            finally
            {
                con.Close();            }
            return null;
        }
    public DataSet qu()
    {
      
       try
       {
           ds = ds.Tables["student"];无法将类型“System.Data.DataTable”隐式转换为System.Data.DataSet”      }
       catch (Exception x)
       {
          MessageBox.Show(("等待数秒后请按‘确定’"));
      }
       
    }
        public DataSet returnDS 
        { 
            
        get 
         { 
            return ds;
           
         } 
        } 
    }
}

解决方案 »

  1.   

     public DataSet start(string sql)“SourceReadDemo.Class1.start(string):并非所有的代码路径都返回值 你方法是需要返回DataSet的,但是你并没有返回所以出错
    ds = ds.Tables["student"];无法将类型“System.Data.DataTable”隐式转换为System.Data.DataSet” 
    ds.Tables["student"];得到的是有个DataTable,所以没办法转换
    直接DataTable dt =ds.Tables["student"];这样才可以
      

  2.   

    直接DataTable dt =ds.Tables["student"];这样才可以
      

  3.   

     public void start(string sql)“SourceReadDemo.Class1.start(string):并非所有的代码路径都返回值         { 
                this.sql = sql; 
                
                //启动线程 
                flag = true; 
                flag1 = true; 
                thread = new Thread(new ThreadStart(threadProc)); 
                thread1 = new Thread(new ThreadStart(threa1)); 
                thread.Start(); 
                thread1.Start(); 
                thread.Priority = ThreadPriority.Highest;//将读数据线程优先 
                
    }DataTable dt = ds.Tables["student"];
      

  4.   

    public DataSet start(string sql)“SourceReadDemo.Class1.start(string):并非所有的代码路径都返回值         { 
                this.sql = sql; 
                
                //启动线程 
                flag = true; 
                flag1 = true; 
                thread = new Thread(new ThreadStart(threadProc)); 
                thread1 = new Thread(new ThreadStart(threa1)); 
                thread.Start(); 
                thread1.Start(); 
                thread.Priority = ThreadPriority.Highest;//将读数据线程优先 
                  要return 一个DataSet的对象
            } 
      

  5.   

     public void start(string sql)“SourceReadDemo.Class1.start(string):并非所有的代码路径都返回值         { 
                this.sql = sql; 
                
                //启动线程 
                flag = true; 
                flag1 = true; 
                thread = new Thread(new ThreadStart(threadProc)); 
                thread1 = new Thread(new ThreadStart(threa1)); 
                thread.Start(); 
                thread1.Start(); 
                thread.Priority = ThreadPriority.Highest;//将读数据线程优先             
            } 
      

  6.   

      public DataSet qu()SourceReadDemo.Class1.qu()”: 并非所有的代码路径都返回值
        {
          
           try
           {
               DataTable dt = ds.Tables["student"];
              
               
          }
           catch (Exception x)
           {
              MessageBox.Show(("等待数秒后请按‘确定’"));
          }
           
        }
    现在前面的没事了
      后面这个方法又不行了!
      

  7.   

     public DataSet qu()SourceReadDemo.Class1.qu()”: 这是什么写法?
    这个的道理是一样的啊
    没有返回值