我想在文本框中显示折扣值 [英] I want to show discount values in textbox

查看:76
本文介绍了我想在文本框中显示折扣值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我的软件中的人我想在文本框中显示折扣值和总和并显示但我得到空值



请帮帮我并告诉我怎么样我这样做了吗?



我尝试了什么:



hello guys in my software I want to show discount values and sum and show in the textbox but I get null values

please help me and tell me how can I do this ?

What I have tried:

DataSet dsa21 = new DataSet();
            DataTable dt21 = new DataTable();
            dsa21.Tables.Add(dt21);
            OleDbDataAdapter da21 = new OleDbDataAdapter();
            da21 = new OleDbDataAdapter("SELECT [Discount] As [Discounts] from [Total] Where [Date] >= #" + dateTimePicker1.Value.ToString("dd/MM/yyyy") + "# AND [Date] < #" + dateTimePicker1.Value.AddDays(1).ToString("dd/MM/yyyy") + "# Group By [Discount]", connection);
            da21.Fill(dt21);
            connection.Close();
            int sum90 = 0;
            for (int i = 0; i < dsa21.Tables[0].Rows.Count; ++i)
            {
                sum90 += Convert.ToInt32(dsa21.Tables[0].Rows[0][0].ToString());
            }
            textBox16.Text = sum90.ToString();

推荐答案

永远不要通过连接来构建SQL查询使用用户输入,它被命名为SQL注入,它对您的数据库很危险并且容易出错。

名称中的单引号和程序崩溃。如果像Brian O'Conner这样的用户输入可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞。

SQL注入 - 维基百科 [ ^ ]

SQL注入 [ ^ ]



Never build an SQL query by concatenating with user inputs, it is named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability.
SQL injection - Wikipedia[^]
SQL Injection[^]

引用:

请帮帮我并告诉我该怎么做

please help me and tell me how can I do this



首先,使用调试器来了解如何获得空值。



当你不明白你的代码在做什么或为什么它做它的作用时,答案是调试器

使用调试器查看代码正在执行的操作。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量,这是一个令人难以置信的学习工具。



调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]

使用Visual Studio 2010进行基本调试 - YouTube [ ^ ]

调试器在这里向您展示您的代码正在做什么以及您的任务是与它应该做的比较。

调试器中没有魔法,它没有发现错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。


First, use the debugger to understanf how you get null values.

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于我想在文本框中显示折扣值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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