Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Guys, i am facing a problem that is i write where not [columnname] = 0 but when i get so it's getting value where column = 0
please look my code once and tell me the solution of this problem
Thanks

What I have tried:

con_string.ConnectionString = @"Provider = Microsoft.ACE.OLEDB.12.0;Data Source =|DataDirectory|\Restaurant.accdb;Persist Security Info=False";
            con_string.Open();
            DataSet dsa1 = new DataSet();
            DataTable dt1 = new DataTable();
            dsa1.Tables.Add(dt1);
            OleDbDataAdapter da1 = new OleDbDataAdapter();
            da1 = new OleDbDataAdapter(string.Format("SELECT [column3] As [Tables],count(Tables) As [QTY] from [Total] Where [column3] like 'DineIn%' Or [Date] Between #{0}# And #{1}# Or not [column1] = 0 Group By [column3]", DateTime.Now.ToShortDateString(), DateTime.Now.AddDays(1).ToShortDateString()), con_string);
            da1.Fill(dt1);
            con_string.Close();
            int sum1 = 0;
            for (int i = 0; i < dsa1.Tables[0].Rows.Count; ++i)
            {
                sum1 += Convert.ToInt32(dsa1.Tables[0].Rows[i][1].ToString());
            }
            Dinein_Orders.Text = sum1.ToString();
Posted
Updated 16-Jul-17 3:53am

1 solution

First off, don't do that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
This isn't causing your problem at the moment, but it's serious - and you need to make sure that the rest of your code is updated as well - or you will lose your DB...

The problem you've noticed is simple: your conditions are all ORed together - which means that if any one of the conditions matches, the whole condition evaluates to true.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900