Click here to Skip to main content
15,894,955 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello Guys am working on my c# application in my application i have itemreport form and when i open my itemreport form on onload so my application automatically closed without any errors please help me how can i solve it whats the error please

What I have tried:

private void ItemReport_Load(object sender, EventArgs e)
{
dateTimePicker1.Text = System.DateTime.Now.AddDays(-1).ToShortDateString();
con_string.Open();
DataSet dsa = new DataSet();
DataTable dt1 = new DataTable();
dsa.Tables.Add(dt1);
OleDbDataAdapter da = new OleDbDataAdapter();
da = new OleDbDataAdapter("SELECT [column2] As [ItemName],count(column2) As [QTY] from [Total] Where [Date] between #" + dateTimePicker1.Value + "# AND #" + dateTimePicker2.Value + "# Group By [column2]", con_string);
da.Fill(dt1);
dataGridView1.DataSource = dt1;
con_string.Close();
}
Posted
Updated 15-Jan-18 11:02am
Comments
BillWoodruff 15-Jan-18 19:27pm    
Single-step into your app and watch for the unexpected. Set break-points and see if you reach them. Clarify your question based on what you observe.

1 solution

C#
da = new OleDbDataAdapter("SELECT [column2] As [ItemName],count(column2) As [QTY] from [Total] Where [Date] between #" + dateTimePicker1.Value + "# AND #" + dateTimePicker2.Value + "# Group By [column2]", con_string);

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability 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 a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
 
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