在C#ms访问中获取值= 0的值 [英] Getting values where values = 0 in C# ms access

查看:68
本文介绍了在C#ms访问中获取值= 0的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys,我正面临一个问题,即我写的地方不是[columnname] = 0但是当我得到它的价值时,列= 0

请查看我的代码并告诉我这个问题的解决方案

谢谢



我尝试过:



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();

推荐答案

首先,不要做那!永远不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。请改用参数化查询。

这不会导致您的问题,但这很严重 - 您需要确保其余代码也已更新 - 否则您将丢失DB ...



你注意到的问题很简单:你的条件都是ORed在一起 - 这意味着如果任何一个条件匹配,整个条件评估为真。
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.


这篇关于在C#ms访问中获取值= 0的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆