如何将空值保存到数据库中的列中 [英] How to save null value into a Column in Database

查看:107
本文介绍了如何将空值保存到数据库中的列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





在我的数据库中有几列如下



Empid(Pk,int ,不是null)

Deptid(int,null),

DeptName(varchar(50),null),

位置(varchar(50) ),null)



从前端..我正在显示一个组合框,其中显示成员是DeptName,而ValueMember是DeptID.Combobox初始值是 - 选择 - -



因此,当用户没有从组合框中选择任何项目时,我想插入/更新具有空值的数据库列。



我尝试通过将selectedvalue转换为int并且当用户没有选择项目时尝试这样做。它因为它为空而抛出错误。



那么如何插入null。

Hi,

In My database there are few columns as

Empid(Pk,int,not null)
Deptid (int, null),
DeptName(varchar(50),null),
Location(varchar(50),null)

From the front end..I am displaying a combobox where the Display member is DeptName and ValueMember is DeptID.Combobox intial value is --Select--

So when user doesn''t select any item from the combobox I want to insert/update database columns with null value.

I tried to do it by converting the selectedvalue to int and when the user doesn''t select an item.It throws an error as it is null.

So how to insert null.

推荐答案

http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm .sqls.doc / sqls562.htm [ ^ ]


检查组合框值,如果它的值是'' - 选择 - ''那么

使用Convert.DBNull而不是combobox.Value
check combobox value and if it''s Value is ''--Select--'' then
use Convert.DBNull instead of combobox.Value


这篇关于如何将空值保存到数据库中的列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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