我的C#应用​​程序自动关闭 [英] My C# application automatically closed

查看:127
本文介绍了我的C#应用​​程序自动关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys正在我的应用程序中处理我的c#应用程序我有itemreport表单,当我在onload上打开我的itemreport表单时,我的应用程序自动关闭而没有任何错误请帮助我如何解决它是什么错误请



我尝试过:



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 [总计] [日期]之间#+ dateTimePicker1.Value +#AND#+ dateTimePicker2.Value +#Group By [column2],con_string);

da.Fill(dt1);

dataGridView1.DataSource = dt1;

con_string.Close();

}

解决方案

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



不是你问题的解决方案,而是你遇到的另一个问题。

永远不要通过连接字符串来构建SQL查询。迟早,您将使用用户输入来执行此操作,这会打开一个名为SQL注入的漏洞,这对您的数据库很容易并且容易出错。

名称中的单引号你的程序崩溃。如果用户输入像Brian O'Conner这样的名称可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞,崩溃是最少的问题,恶意用户输入,并且它被提升为具有所有凭据的SQL命令。

SQL注入 - 维基百科 [ ^ ]

SQL注入 [ ^ ]

按示例进行SQL注入攻击 [ ^ ]

PHP:SQL注入 - 手册 [ ^ ]

SQL注入预防备忘单 - OWASP [ ^ ]


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

解决方案

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


这篇关于我的C#应用​​程序自动关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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