Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:

C#
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();
Posted
Updated 16-Apr-17 20:12pm
v3
Comments
[no name] 16-Apr-17 13:32pm    
You learn how to use the debugger and find out where the null values are coming from. Then you fix it.

1 solution

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[^]

Quote:
please help me and tell me how can I do this

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.
 
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