Hello guys I have got this query that might have in columns klisluz.cena and klisluz.pocet null or DBNull (not sure) values.
May I ask how can I prevent in this sQuery for those columns if there was null so I can insert into datagridview 0 ?
As this is JOIN query I'm not sure where should I implement ISNULL(klisluz.pocet,0) and ISNULL(klisluz.cena)
DataTable dt = new DataTable();
string sZakce = string.Empty;
if (zakce != null && zakce.Text != null)
{
sZakce = zakce.Text;
}
string sQuery = string.Format("SELECT zajsluz.akce, zajsluz.text, klisluz.cena,
klisluz.pocet, klisluz.subkey, zajsluz.ID FROM zajsluz LEFT JOIN klisluz ON
zajsluz.ID = klisluz.IDzajsluz WHERE zajsluz.akce= '{0}' and
ISNULL(klisluz.subkey, '" + vyberradek + "') = '" + vyberradek + "'
GROUP BY klisluz.subkey, zajsluz.akce, klisluz.cena, zajsluz.text,
klisluz.pocet, zajsluz.ID", sZakce);
SqlDataAdapter SDA = new SqlDataAdapter(sQuery, spojeni);
SDA.Fill(dt);
dtg_ksluzby.DataSource = dt;
Thank you for your time.
So far I tried this:
for (int i = 0; i < (dtg_ksluzby.Rows.Count - 0); i++)
{
if (dtg_ksluzby.Rows[i].Cells["pocet"].Value == null ||
(string)dtg_ksluzby.Rows[i].Cells["pocet"].Value == string.Empty)
{
dtg_ksluzby.Rows[i].Cells["pocet"].Value = 0;
}
if (dtg_ksluzby.Rows[i].Cells["cena"].Value == null ||
(string)dtg_ksluzby.Rows[i].Cells["cena"].Value == string.Empty)
{
dtg_ksluzby.Rows[i].Cells["cena"].Value = 0;
}
}
But got exception that those column names cannot be found.
SELECTclause. Check the answer by @Soner