数量增量不适用于带有数字的leters [英] Quantity increment dont work with leters just with numbers

查看:73
本文介绍了数量增量不适用于带有数字的leters的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Some help
 
In line 10 setup IsLetterOrDigit..
 
When add some value in datagrid
 
 Line 34-39 have problem...
 
Every time add new row, if put number  it ok kolicina (quantity go up +1), if is bar code type vm1403 add new row...not kolicina (quantity) +1...why? Some help?

    int cqty = Convert.ToInt32(row.Cells["kolicina"].Value) + 1;  
      
                              if (textBox1.Text == row.Cells["bar_kod"].Value.ToString())  
                              {  
                                  row.Cells["kolicina"].Value = cqty;  





我的尝试:





What I have tried:

private void prijavaAction()  
      {  
          PullData();  
                
                
          int sno = dataGridView1.Rows.Count + 1;  
  
          SqlConnection con2 = new SqlConnection(con);  
  
          if (textBox1.Text.All(char.IsLetterOrDigit))  
  
          {  
              string queryString = "select [bar_kod], [naziv], [cijena_sa_porezom] from dbo.roba_usluge WHERE [bar_kod] = '" + textBox1.Text + "'";// pronaci artikl u bazi                
              using (SqlConnection connection = new SqlConnection(con))  
              {  
                  SqlCommand command = new SqlCommand(queryString, connection);  
                  connection.Open();  
                  SqlDataReader reader = command.ExecuteReader();  
  
  ///////////////////////////////////////////

here is error
                  var itemAndPrice = textBox1.Text;  
  
                  var SingleRow = (from Rows in dataGridView1.Rows.Cast<DataGridViewRow>() where !Rows.IsNewRow && Rows.Cells["bar_kod"].Value.ToString().ToUpper() == textBox1.Text.ToUpper() select Rows).FirstOrDefault();  
  
  
                  if (reader.Read())  
                  {  
  
                      bool barcodeexist = false;  
                      foreach (DataGridViewRow row in dataGridView1.Rows)  
                      {  
                          int cqty = Convert.ToInt32(row.Cells["kolicina"].Value) + 1;  
  
                          if (textBox1.Text == row.Cells["bar_kod"].Value.ToString())  
                          {  
                              row.Cells["kolicina"].Value = cqty;  
   ///////////////////////////////////////////


                              foreach (DataGridViewRow g1 in dataGridView1.Rows)  
                              {  
  
  
                                  g1.Cells["ukupno"].Value = (Convert.ToDouble(g1.Cells["kolicina"].Value) * Convert.ToDouble(g1.Cells["cijena"].Value)).ToString("0.00");  
  
                              }  

推荐答案

string queryString = "select [bar_kod], [naziv], [cijena_sa_porezom] from dbo.roba_usluge WHERE [bar_kod] = '" + textBox1.Text + "'";



没有必要解决你的问题,但你有另一个问题。

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

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

SQL注入 - 维基百科 [ ^ ]

SQL注入 [ ^ ]

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

PHP:SQL注入 - 手册 [ ^ ]

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

我该怎么办?解释没有技术术语的SQL注入? - 信息安全堆栈交换 [ ^ ]


Not necessary 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[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]

引用:

每次添加新行,如果把数字好吧kolicina(数量上升+1),如果是条形码类型vm1403添加新行...不是kolicina(数量)+1 ...为什么?一些帮助吗?

Every time add new row, if put number it ok kolicina (quantity go up +1), if is bar code type vm1403 add new row...not kolicina (quantity) +1...why? Some help?



你的代码没有你想象的那样,或者你不明白为什么!



那里是一个几乎通用的解决方案:逐步在调试器上运行代码,检查变量。

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

调试器中没有魔法,它不知道你的代码应该做什么,它没有找到错误,它只是通过向你显示正在发生的事情来帮助你。当代码没有达到预期的效果时,你就接近了一个错误。

要查看你的代码在做什么:只需设置断点并查看代码是否正常运行,调试器允许你执行第1行第1行,并在执行时检查变量。



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


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

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



在Visual Studio中调试C#代码 - YouTube [ ^ ]



这里的调试器只显示你的代码正在做什么,你的任务是与它应该做什么进行比较。


Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
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 know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
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.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

Debugging C# Code in Visual Studio - YouTube[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.


这篇关于数量增量不适用于带有数字的leters的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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