如何将空值保存到数据库中的列中

问题描述:





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



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