2个DataGridViews的结果相同?

时间:2019-06-14 14:28:54

标签: c# winforms datagridview datasource

需要一些简单代码的帮助

这是针对Visual Studio c#Win Forms

   dgvScad.DataSource = 
   dataProvider.getAttestatiByScad(DateTime.Today.AddDays(dayScad), 
   DateTime.Today);

   dgvProve.DataSource = 
   dataProvider.getAziendaliByScad(DateTime.Today.AddDays(dayScad), 
   DateTime.Today);

a

        public DataTable getAttestatiByScad(DateTime scadenza1, DateTime scadenza2)
        {
            string sql = "SELECT CONCAT(Dipendenti.cognome, ' ', Dipendenti.nome) AS Nome, Attestati.nome AS Attestato, AssAttestati.scadenza AS Scadenza " +
                " FROM Attestati INNER JOIN(AssAttestati INNER JOIN Dipendenti" +
                " ON AssAttestati.matricola=Dipendenti.matricola) " +
                " ON Attestati.ID=AssAttestati.attestato " +
                " WHERE AssAttestati.scadenza<=@scadenza1 AND AssAttestati.scadenza>=@scadenza2;";

            DataTable dt = db.EseguiQueryWithParams
                (
                sql,
                new SqlParameter("@scadenza1", scadenza1),
                new SqlParameter("@scadenza2", scadenza2)
                );

            return dt;
        }



        public DataTable getAziendaliByScad(DateTime scadenza1, DateTime scadenza2)
        {
            string sql = "SELECT Aziendali.nome, Aziendali.scadenza FROM Aziendali WHERE Aziendali.scadenza<=@scadenza1 AND Aziendali.scadenza>=@scadenza2";

            DataTable dt = db.EseguiQueryWithParams
                (
                sql,
                new SqlParameter("@scadenza1", scadenza1),
                new SqlParameter("@scadenza2", scadenza2)
                );

            return dt;
        }

public DataTable EseguiQueryWithParams(string sql, params SqlParameter[] parameters)
        {
            apriConnessione();
            string nometab = "dump";
            cmd.CommandText = sql;

            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Parameters.AddRange(parameters);
            try
            {
                adp = new SqlDataAdapter(cmd);
                if (dset.Tables[nometab] != null)
                    dset.Tables[nometab].Clear();

                adp.Fill(dset, nometab);
                DataTable d = dset.Tables[nometab];
                //d.Columns;
                return d;
            }
            catch (Exception e)
            {
                throw e;
                //throw new System.Exception("Errore nella lettura della tabella");

            }
            finally
            {
                adp.Dispose();
                cmd.Dispose();
                ChiudiConnessione();
            }

        }

我期望输出结果不同,但是对于一个DataGridView和另一个DataGridView,我看到的输出都是相同的。

希望你能明白我的意思,我的英语不太好。

您的帖子似乎主要是代码;请添加更多详细信息。

您的帖子似乎主要是代码;请添加更多详细信息。?

0 个答案:

没有答案