搜索DataGrid时出现"DBNull"问题(VB2008) [英] Problems with 'DBNull' when searching a DataGrid (VB2008)

查看:87
本文介绍了搜索DataGrid时出现"DBNull"问题(VB2008)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!我是一名新手程序员(一个入门级课程),并且正在为我的朋友写一个程序作为礼物.他是电影爱好者,并且拥有此Excel电子表格以及他所观看的所有电影.我将电子表格转换为Access数据库, 然后在我的程序中使用该数据库.我一直在教科书(戴安娜·扎克(Diane Zak)用Microsoft Visual Basic编程)中查看该示例,直到我输入了查找电影标题"(Find Movie Title)为止,一切都一直有效.按钮.我希望能够搜索该列 电影标题"用户输入的标题(无论是整个标题还是仅几个字符)

Hello! I'm a newbie programmer (one introductory level class), and I'm writing a program for my friend as a gift. He's a movie lover, and has this Excel spreadsheet with all the movies he's watched in it. I converted the spreadsheet to an Access database, then used that database in my program. I've been going by the example in my textbook (Programming with Microsoft Visual Basic by Diane Zak), and everything been working until I put in a "Find Movie Title" button. I want to be able to search the column "Movie Title" for a title input by the user (whether it's the whole title or just a few characters)

代码如下:

私人

btnFindTitle_Click( ByVal As 对象 ByVal e As System.EventArgs) 手柄 btnFindTitle.Click

Sub btnFindTitle_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFindTitle.Click

 

 

 

 

 

 

MoviesBindingSource.DataSource = Records.AsDataView

MoviesBindingSource.DataSource = Records.AsDataView

 

一切正常,直到我在文本框中输入内容.然后程序冻结,这部分代码在MoviesDataSet.Designer.vb中突出显示:

Everything works until I input something into the text box. Then the program freezes, and this chunk of code is highlighted in the MoviesDataSet.Designer.vb:

 

显示以下消息:表'Movies'中'Movie Title'列的值为DBNull.

With this message: "The value for column 'Movie Title' in table 'Movies' is DBNull."

我不知道这是什么,我曾尝试在Google上搜索答案,但没有发现任何帮助.有人可以告诉我该怎么做吗?

I have no idea what that is, and I've tried searching Google for answers, but I haven't found anything helpful. Can anybody tell me what I need to do to fix it? Thank you so much!

推荐答案

Hello Sabrielsja,

Hello Sabrielsja,

以下是尝试绕过InputBox,硬代码(因此也没有大写字母)的建议,您可以轻松地将其添加回何处.请注意LINQ语句的构造方式,然后检查您的方式构造您的LINQ 声明.

The following is a suggestion to try which bypasses the InputBox, hard codes (thus no upper casing either) the where criteria, you can easily add this back in. Take note how the LINQ statement is constructed then examine how you constructed your LINQ statement.

为演示加载模拟数据


    Public Function LoadMovies() As DataSet
        Dim ds As New DataSet
        Dim dt As New DataTable With {.TableName = "Movies"}

        With dt.Columns
            .AddRange(New DataColumn() _
            { _
             New DataColumn("Identifier", GetType(System.Int32)), _
             New DataColumn("Title", GetType(System.String)), _
             New DataColumn("Rating", GetType(System.String)) _
             })
        End With

        dt.Columns("Identifier").AutoIncrement = True
        dt.Columns("Identifier").AllowDBNull = False
        dt.Columns("Identifier").ReadOnly = True

        dt.Rows.Add(New Object() {Nothing, "Crank", "****"})
        dt.Rows.Add(New Object() {Nothing, "Contact", "*****"})
        dt.Rows.Add(New Object() {Nothing, "Taken", "*****"})
        dt.Rows.Add(New Object() {Nothing, "Rambo", "***"})

        ds.Tables.Add(dt)
        Return ds

    End Function


这篇关于搜索DataGrid时出现"DBNull"问题(VB2008)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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