你调用的对象是空的

你调用的对象是空的

本文介绍了你调用的对象是空的!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我创建了一个学生管理系统,它给我一个错误对象引用未设置为对象的实例,同时更新DataGridView内的数据...更新按钮在我插入TreeView之前成功运行...从那以后我插入TreeView ..Update按钮给出错误...错误显示在SQL命令行上...



我尝试过:



这是我的代码...



I created a Student Management System and It gives me an error "Object Reference Not set to an Instance of an Object" while updating data inside the DataGridView...Update button worked successfully before i Insert a TreeView...Ever since i inserted the TreeView..Update Button Gives an error...The error shows on the SQL Command Line...

What I have tried:

This is my code...

Private Sub UpdateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
        Try
            Dim upcom11 As New SqlCommand("Update Students SET FullName='" & ffname.Text & "',FirstName='" & firstname.Text & "',LastName='" & lastname.Text & "',Gender='" & male.Checked Or female.Checked & "',Address='" & address1.Text & "',Contact='" & contact1.Text & "',NIC='" & nic1.Text & "',Email='" & Email1.Text & "',DateOfBirth='" & DOB1.Value & "' Where StudentID = '" & Registered_Students.Registered.CurrentRow.Cells(0).Value & "' ", connection)
            If Registered_Students.Registered.SelectedRows.Count > 0 Then
                connection.Open()
                upcom11.ExecuteNonQuery()
                connection.Close()
                Me.Close()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

推荐答案



Quote:

对象引用未设置为对象的实例!

Object reference not set to an instance of an object!



使用调试器查看错误的位置并检查变量,其中1个不是预期的。应该设置该对象的命令失败了,但是在你尝试使用它之前你不知道。

-----

有一个工具允许您查看代码正在执行的操作,其名称为调试程序。它也是一个很好的学习工具,因为它向你展示了现实,你可以看到哪种期望与现实相符。

当你不明白你的代码在做什么或为什么它做它做的时候,答案就是答案是调试器

使用调试器查看代码正在执行的操作。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量。



[]



[]

[]

[ []

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

调试器中没有魔法,它没有发现错误,它只是帮助你到。当代码没有达到预期的效果时,你就会接近一个错误。


Use the debugger to see where is the error and check the variables, 1 of them is not what is expected. The command that is supposed to set that object have failed, but you don't know until you try to use it.
-----
There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger 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[^]
Visual Basic / Visual Studio Video Tutorial - Basic Debugging - YouTube[^]
Visual Basic .NET programming for Beginners - Breakpoints and Debugging Tools[^]
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 find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于你调用的对象是空的!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:54