我正尝试在vb.net上更新我的数据库(MySQL
)中的记录。我想根据文本框更新记录。我正在使用循环,因为我有多个文本框使用Ctype的数量和价格不同的名称。 我的代码的样品是:使用Ctype创建对象时出错(....)
j=58
For i As Integer = 1 To 19 Step 1
Dim pricebox As TextBox = CType(Me.Controls("TextBox" + CStr(i)), TextBox)
Dim qtybox As TextBox = CType(Me.Controls("TextBox" + CStr(j)), TextBox)
sqlcommand.Parameters.AddWithValue("@id", i)
sqlcommand.Parameters.AddWithValue("@qty", CInt(qtybox.Text))
sqlcommand.Parameters.AddWithValue("@price", CInt(pricebox.Text))
j=j-1
Next
但是在运行时期间,它抛出:
“对象引用不设置为一个实例”上线 "sqlcommand.Parameters.AddWithValue("@qty “,CInt(qtybox.Text))”
任何帮助将不胜感激,谢谢。
的【什么是一个NullReferenceException,如何解决呢?(可能的复制https://stackoverflow.com/questions/4660142/what-is -a-nullreferenceexception-how-do-i-fix-it) –
但我无法使用“new”为“qtybox”创建新实例。那么我该怎么做呢? –
这不是帖子告诉你要做的唯一事情,你知道的。你必须找出_什么是空的,并且它的原因是空的......这里都有解释。 –