I try to get sum of all of my TUTAR
column with SQL Server in C# but can't do it. When I try the code above it works fine.
string qry = "SELECT * FROM BENZIN WHERE DATE>='" + invoicedate + "' AND DATE<='" + invoicedate1 + "' AND PLATE= '" + plaka + "'";
conn.Open();
SqlDataReader dr = new SqlCommand(qry,conn).ExecuteReader();
while (dr.Read())
{
var item = new ListViewItem();
item.SubItems.Add(dr["TUTAR"].ToString());
listView1.Items.Add(item);
}
But when I try
string qry = "SELECT SUM(TUTAR) FROM BENZIN WHERE DATE LIKE '%" + yılcombobox.Text + "'";
MessageBox.Show(qry);
conn.Open();
SqlDataReader dr = new SqlCommand(qry, conn).ExecuteReader();
while (dr.Read())
{
yıllıktutar = dr.GetValue(0).ToString();
}
MessageBox.Show(yıllıktutar);
it returns nothing. yılcombobox is a textbox and it contains selected year like 2017 or 2018 or something like that