DataSet,他的参数是一个,如果我有个表该怎么做呢
比如:
//DataSet 
public DataSet getDataSet(string sql,string table)
        {
            mysqlcon.Open();            MySqlDataAdapter thisadapter = new MySqlDataAdapter();            thisadapter.SelectCommand = new MySqlCommand(sql, mysqlcon);
            
            DataSet ds = new DataSet();
            thisadapter.Fill(ds, table);
           
            mysqlcon.Close();
            return ds;
        }
在这里调用我的DataSet 
//
public void dd(string mysql,string table)
        {
            DB.db Com = new db();
            StringBuilder str = new StringBuilder();
            str.Append(mysql);
            Cr_Mat_Print cr_mat = new Cr_Mat_Print();
                             cr_mat.SetDataSource(Com.getDataSet(str.ToString(), table));
            crystalReportViewer1.ReportSource = cr_mat;
        }//调用我的dd(string mysql,string table)public partial class F_Mat_Print : Form
    {
        public F_Mat_Print()
        {
            InitializeComponent();
            dd("select m.id,pa.Description,m.Counts,m.Units,m.Sizes,p.PatternNo from materials m,pattern p,part pa where m.id=66 and m.PartID=pa.id group by m.id", "参数该怎么写呀");
        }请大家帮忙!!

解决方案 »

  1.   

    DataSet ds = new DataSet();//在公共的地方调用public DataSet getDataSet(string sql,string table) 
            { 
                mysqlcon.Open();             MySqlDataAdapter thisadapter = new MySqlDataAdapter();             thisadapter.SelectCommand = new MySqlCommand(sql, mysqlcon); 
                 
               //  
                thisadapter.Fill(ds, table); 
                
                mysqlcon.Close(); 
                return ds; 
            } 
    public void dd(string mysql,DataTable table) 
            { 
                DB.db Com = new db(); 
                StringBuilder str = new StringBuilder(); 
                str.Append(mysql); 
                Cr_Mat_Print cr_mat = new Cr_Mat_Print(); 
                                 cr_mat.SetDataSource(Com.getDataSet(str.ToString(), table)); 
                crystalReportViewer1.ReportSource = cr_mat; 
            } 
    //调用我的dd(string mysql,string table) public partial class F_Mat_Print : Form 
        { 
            public F_Mat_Print() 
            { 
                InitializeComponent(); 
                dd("select m.id,pa.Description,m.Counts,m.Units,m.Sizes,p.PatternNo from materials m,pattern p,part pa where m.id=66 and m.PartID=pa.id group by m.id", ds.Table[0]); 
            } 
      

  2.   

    如果是多表把最后那个传参的地方改为
    ds.Tables["表名"]
      

  3.   

    getDataSet().tables["表名"]
    getDataSet().tables[TableIndex]
      

  4.   

    没看明白呀,
    //调用我的dd(string mysql,string table) public partial class F_Mat_Print : Form 
        { 
            public F_Mat_Print() 
            { 
                InitializeComponent(); 
                dd("select m.id,pa.Description,m.Counts,m.Units,m.Sizes,p.PatternNo from materials m,pattern p,part pa where m.id=66 and m.PartID=pa.id group by m.id", ds.Table[0]); 
            } ds.Table[0]什么意思呀,里面几个表呀,请指教,谢谢
      

  5.   

    随便写个表名就行
    dd("select m.id,pa.Description,m.Counts,m.Units,m.Sizes,p.PatternNo from materials m,pattern p,part pa where m.id=66 and m.PartID=pa.id group by m.id","a");  
     
      

  6.   

    ds.Table[0]什么意思呀
    ------------------
    ds.Table[0]指你的DataSet中的第一张表
      

  7.   

    随便写个表名是不行的,那样的话根本找不到自己所需要的表,其实我的要求很明确了,看我第一次的发贴,我的多个表怎样传到
    public void dd(string mysql,string table) 
            { 
                DB.db Com = new db(); 
                StringBuilder str = new StringBuilder(); 
                str.Append(mysql); 
                Cr_Mat_Print cr_mat = new Cr_Mat_Print(); 
                                 cr_mat.SetDataSource(Com.getDataSet(str.ToString(), table)); 
                crystalReportViewer1.ReportSource = cr_mat; 
            } 里面,然后cr_mat.SetDataSource(Com.getDataSet(str.ToString(), table)); 里面的table怎样表示才是多个表,然后传到
    //DataSet  
    public DataSet getDataSet(string sql,string table) 
            { 
                mysqlcon.Open();             MySqlDataAdapter thisadapter = new MySqlDataAdapter();             thisadapter.SelectCommand = new MySqlCommand(sql, mysqlcon); 
                 
                DataSet ds = new DataSet(); 
                thisadapter.Fill(ds, table); 
                
                mysqlcon.Close(); 
                return ds; 
            } 
    进行执行
    关键是
     dd("select m.id,pa.Description,m.Counts,m.Units,m.Sizes,p.PatternNo from materials m,pattern p,part pa where m.id=66 and m.PartID=pa.id group by m.id", "参数该怎么写呀"); 
            } 
    的参数
    这回大家明白了吧请大家看一下
      

  8.   

    不好意思,真看错了,那个参数你可以用你的表名来填充thisadapter.Fill(ds, table);  各个表的名字是不会有重复的. dd("select m.id,pa.Description,m.Counts,m.Units,m.Sizes,p.PatternNo from materials m,pattern p,part pa where m.id=66 and m.PartID=pa.id group by m.id", "tableName");  
      

  9.   

    QQQQAnnie
    你好,也可能我太笨了,真的不好意思麻烦你了,可是,我照着你说的做了,还是不行的
    thisadapter.Fill(ds, table); 这句话应该是在DataSet里面写吧,可是我把
    dd("select m.id,pa.Description,m.Counts,m.Units,m.Sizes,p.PatternNo from materials m,pattern p,part pa where m.id=66 and m.PartID=pa.id group by m.id", "tableName");   
    的参数随便起了个名字,结果还是不行的,根本就没找到这3个表
    麻烦你在帮一下
    谢谢你!!
      

  10.   

    我这有个例子:(你的是C/S模式的吧)DataSet ds=new DataSet();SqlConnection con=new SqlConnection();
    con.ConnectionString="连库";
    con.open();
    SqlCommand com=new SqlCommand();
    com.Connection=con;
    com.CommandText="select * from tableName";
    SqlDataAdapter sda=new SqlDataAdapter();
    sda=new SqlDataAdapter(com);
    sda.Fill(ds,"tableName");this.bindingSource1.DataSource=ds;
    this.bindingSource1.DataMember="tableName";this.DataGridView1.DataSource=this.bindingSource1;
      

  11.   

    我知道你是什么错误了,不是参数表名那块的错误,是你的SQL语句的错误,你那样写,系统会不知道是那个表
    你的这两个表不是有外键关系吗,你用join on语句吧
    实在不行用union语句
    这是我做的例子
     private void AllTable_Load(object sender, EventArgs e)
            {
                SqlConnection mysqlcon = new SqlConnection();
                mysqlcon.ConnectionString = "Server=localhost;dataBase=net;trusted_connection=true";
                mysqlcon.Open();            SqlDataAdapter thisadapter = new SqlDataAdapter();
                string sql = "select t1.id as id ,t1.dj as dj,t2.name as name from t1 join t2 on t1.id=t2.t1id";
                thisadapter.SelectCommand = new SqlCommand(sql, mysqlcon);            DataSet ds = new DataSet();
                thisadapter.Fill(ds, "table");            this.bindingSource1.DataSource = ds;
                this.bindingSource1.DataMember = "table";            this.dataGridView1.DataSource = this.bindingSource1;
            }