System.NullReferenceException {“对象引用未设置为对象的实例 [英] System.NullReferenceException {“Object reference not set to an instance of an object

查看:117
本文介绍了System.NullReferenceException {“对象引用未设置为对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim cmdg As OleDbCommand
Dim sqlr As String
Dim sqlra As New OleDbCommand
Dim conb = New OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;data source=inbound.mdb")

       sqlr = "Insert Into ManualDO (BLNo,DONo,ReleaseTo,Vessel,Voyage,FromPort,ETA,NoCont,Weight,Measure) Values ('" & IIf(rd1![NoBL] = "", " ", rd1![NoBL]) & "' , '" & Strings.Right(IIf(rd1![MNoBL] = "", rd1![NoBL], rd1![MNoBL]), 7) & "','" & tempCust & "','" & IIf(UCase(rd1![NMAngk]) = "", " ", UCase(rd1![NMAngk])) & "',V. '" & rd1![NoVoy] & "','" & IIf(Trim(rd1![NMPort]) = "", " ", Trim(rd1![NMPort])) & "','" & Format(rd1![TGTiba], "MMMM DD YYYY") & "','" & IIf(NoCont = "", " ", NoCont) & "','" & Format(Trim(str(rd1![Bruto])), "###,##0.000") & " KGS','" & Format(Trim(str(rd1![Volume])), "###,##0.000") & " M3')"

cmdg = New OleDbCommand(sqlr, conb)
conb.Open()
sqlra = New OleDbCommand(sqlr, conb)
sqlra.ExecuteNonQuery()



您能帮我这段代码有什么问题吗?
该错误出现在行sqlr查询中.



Could you help me whats the matter with this code ?
That error appear in line sqlr query.
Thanks before

推荐答案

之前,谢谢.我们不能.

原因很简单,您做错了两件事:首先,您将字符串连接起来以形成SQL命令,这是非常危险的-它使您容易受到SQL注入攻击的攻击,这可能会损坏或破坏数据库.请改用参数化查询.

其次,这取决于您的数据:而我们无权访问.因此,请使用调试器.在行上放置一个断点,并在到达断点时依次检查语句的每个部分.当您发现哪个部分为空时,您可以开始回溯cdoe找出原因.但是我们不能!
No. We can''t.

The simple reason is that you are doing two things wrong: firstly you are concatenating strings to form an SQL command, which is extremely dangerous - it leave you wide open to SQL Injection attacks which can damage or destroy your database. Use parametrized queries instead.

Secondly, it''s down to your data: and we don''t have access to that. So use the debugger. Put a breakpoint on the line, and examine each part of the statement in turn when it hits the breakpoint. When you find which part is null, you can start looking back in your cdoe to find out why. But we can''t!


这篇关于System.NullReferenceException {“对象引用未设置为对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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