如何修复从“DB null”类型到字符串的转换无效 [英] How to fix conversion from type 'DB null' to string is not valid

查看:92
本文介绍了如何修复从“DB null”类型到字符串的转换无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图制作DataGridView Click事件,只要光标点击它将在文本框中显示的数据具有相同的数据



我尝试过的:



im trying to make the DataGridView Click Event whenever the cursor clicked the data it will show on the textbox with the same data

What I have tried:

Private Sub dgv_CellMouseClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgv.CellMouseClick
        tb_nip.Text = dgv.Rows(e.RowIndex).Cells(0).Value
        tb_nk.Text = dgv.Rows(e.RowIndex).Cells(1).Value
        tb_tm.Text = dgv.Rows(e.RowIndex).Cells(2).Value
        tb_prsn.Text = dgv.Rows(e.RowIndex).Cells(3).Value
    End Sub

推荐答案

问题很简单:您的数据库包含一个可以 - 并且确实 - 包含空值的列,并且您的代码不允许那。

要做的第一件事就是决定你的数据库是否正确,或者是否需要更改它 - 以及管理它的规则。

所以首先考虑一下列 - 它应包含哪些数据?当它为空时它意味着什么?您的应用应该如何处理空数据?或者你应该阻止空值进入你的数据库开始吗?



如果空值有效,那么你需要决定是否应该将它们发布到你的应用程序中 - 因为null字符串完全有效,但与空字符串不同,需要在您的应用中进行检查和处理。



如果不是,那么你需要了解他们是如何进入的,并用实际数据替换它们......



当你决定了那个地段后,你就可以开始实施修复对于你的问题,但直到那时!
The problem is simple: your database contains a column which can - and does - contain null values, and your code does not allow for that.
The first thing to do is decide if your DB is correct, or if that - and the rules governing it - need to be changed.
So start by thinking about the column - what data should it contain? What does it "mean" when it's null? What should your app be doing with null data? Or should you be preventing nulls getting into your db to begin with?

If nulls are valid, then you need to decide if they should be promulgated into your app - because a null string is perfectly valid, but is different from an empty string and needs to be checked for and processed in your app.

If they aren't, then you need to find out how they got in there, and replace them with actual data...

When you have decided that lot, you can start implementing a "fix" for your problem, but not until then!


这篇关于如何修复从“DB null”类型到字符串的转换无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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