我如何解决“值不能为空参数名称:字符串” [英] How do I solved "the value cannot be null parameter name: string"

查看:576
本文介绍了我如何解决“值不能为空参数名称:字符串”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 Dim code As String 
Dim name As String
Dim category As String
Dim size As String
Dim productprice As Decimal
Dim soldprice As Decimal
Dim count As String
Dim totalsales As Decimal
Dim stock As String
Dim newstocks As String
Dim pinvoice As String

For i = 0 To DGVReceipt.Rows.Count - 1
code = DGVReceipt.Rows(i).Cells(0).Value
name = DGVReceipt.Rows(i).Cells(1)。价值
类别= DGVReceipt.Rows(i).Cells(2).Value
size = DGVReceipt.Rows(i).Cells(3).Value
productprice = Decimal.Parse(DGVReceipt .Rows(i).Cells(4).Value)
sellingprice = Decimal.Parse(DGVReceipt.Rows(i).Cells(5).Value)
count = DGVReceipt.Rows(i)。单元格(6).Value
totalsales = Decimal.Parse(DGVReceipt.Rows(i).Cells(7).Value)
stock = DGVReceipt.Rows(i).Cells(8).Value
newstocks = DGVReceipt.Rows(i).Cells(9).Value
pinvoice = DGVReceipt.Rows(i).Cells(10).Val ue
next

MyNonQuery(String.Format(insert into boyscout_pos.tbltransaction(Purchase_Invoice,Receipt_No,Date,Product_Code,Product_Name,Category,Size,Product_Price,Selling_Price,Stock_Out,Total)值( '{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', {8}','{9}','{10}'),pinvoice,receiptNo.Text,transactiondate.Text,代码,名称,类别,尺寸,productprice,sellprice,count,totalsales))





我尝试过:



1st things 1st ,我有一个价值的数据,如(250.75)。我想把它存储到我的mysql数据库中,所以转换productprice&像上面的代码,但实际上销售价格。我遇到一个警告值不能为null参数名:String。



如何解决这个问题。

解决方案

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

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

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

SQL注入 - 维基百科 [ ^ ]

SQL注入 [ ^ ]

 Dim code As String
 Dim name As String
 Dim category As String
 Dim size As String
 Dim productprice As Decimal
 Dim sellingprice As Decimal
 Dim count As String
 Dim totalsales As Decimal
 Dim stock As String
 Dim newstocks As String
 Dim pinvoice As String

 For i = 0 To DGVReceipt.Rows.Count - 1
    code = DGVReceipt.Rows(i).Cells(0).Value
    name = DGVReceipt.Rows(i).Cells(1).Value
    category = DGVReceipt.Rows(i).Cells(2).Value
    size = DGVReceipt.Rows(i).Cells(3).Value
    productprice = Decimal.Parse(DGVReceipt.Rows(i).Cells(4).Value)
    sellingprice = Decimal.Parse(DGVReceipt.Rows(i).Cells(5).Value)
    count = DGVReceipt.Rows(i).Cells(6).Value
    totalsales = Decimal.Parse(DGVReceipt.Rows(i).Cells(7).Value)
    stock = DGVReceipt.Rows(i).Cells(8).Value
    newstocks = DGVReceipt.Rows(i).Cells(9).Value
    pinvoice = DGVReceipt.Rows(i).Cells(10).Value
next

MyNonQuery(String.Format("insert into boyscout_pos.tbltransaction(Purchase_Invoice,Receipt_No,Date,Product_Code,Product_Name,Category,Size,Product_Price,Selling_Price,Stock_Out,Total) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')", pinvoice, receiptNo.Text, transactiondate.Text, code, name, category, size, productprice, sellingprice, count, totalsales))



What I have tried:

1st things 1st, I had a data that value of price like (250.75). I want to stored it into my mysql database, So convert productprice & sellingprice like what the code above but in effect. I encountered a warning "the value cannot be null parameter name: String".

How do I solved this.

解决方案

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


这篇关于我如何解决“值不能为空参数名称:字符串”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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