你调用的对象是空的

发布于 2024-09-30 11:04:43 字数 692 浏览 0 评论 0原文

我有一个具有搜索功能的表单 - 单个文本字段和命令按钮;填写文本字段后,将执行数据库查询,并且结果(如果返回一个结果)通过动态控制字段显示在表单上。

第一次使用搜索功能时,会创建字段并从数据库返回数据,但是重新运行搜索功能时,我收到错误“对象引用未设置为对象的实例” ,错误发生在:

initSearch(txtSearchInput.Text)

我猜测我没有正确处理此类使用的文本字段,任何人都可以建议我还应该怎么做?

txtSearchInput 不是动态字段,它是通过设计模式创建的,命令按钮也是如此。上面的代码位于命令按钮单击事件中:

 Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        Try
            initSearch(txtSearchInput.Text)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error Encountered")
        End Try


    End Sub

任何帮助将不胜感激。

谢谢,

马特

I have a form which has a search feature - a single text field and command button; when the text field is filled-in a database query is executed and the result (if one result returned) is shown on the form via dynamic control fields.

When the search feature is used for the first time, the fields are created and the data is returned from the database, however when the search feature is re-ran I am getting the error "Object Reference not set to an instance of an object", the error occurs at:

initSearch(txtSearchInput.Text)

I am guessing that I am not handling the textfield properly for this type of use, can anyone please advise how else I should be doing this?

The txtSearchInput is not a dynamic field, it has been created through the design mode, the same for the command button. The above code is located in the command button On Click event:

 Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        Try
            initSearch(txtSearchInput.Text)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error Encountered")
        End Try


    End Sub

Any help would be greatly appreciated.

Thanks,

Matt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

莫言歌 2024-10-07 11:04:43

任何帮助将不胜感激。

该错误不在您发布的代码中。 TextBox 的 Text 属性以及对 Form Textbox 的引用不会突然变为 null。

您可能必须调试到 initSearch

Any help would be greatly appreciated.

The error is not in the code you posted. The Text property of a TextBox, and the reference to a Form Textbox don't become null all of a sudden.

You probably have to debug into initSearch

月依秋水 2024-10-07 11:04:43

您是否在调试器中测试 txtSearchInput 是否为空?

异常可能是从 initSearch 函数中冒出来的,最好的方法是调试代码。

Did you test in the debugger if txtSearchInput is null?

Exception could be bubbling up from initSearch function, best way is to debug your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文