C#,Sqlserver空值 [英] C#,Sqlserver Null values

查看:89
本文介绍了C#,Sqlserver空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是Phani Kumar,我正在开发一个应用程序,有时在应用程序中有文本框,有时我在textBox中输入文本,但有时,我输入Data,但有时我不输入数据.但是,当我不输入数据时,将其保存在Sqlserver数据库中时,应将其另存为"NULL"

请尽快答复我

Hi,

This is Phani Kumar i am developing an application, I have textbox in an application some time i enter text into textBox but some times, i enter Data and but sometimes, I donot enter data. But when i do not Enter Data, when i save it in Sqlserver DataBase it should be saved as "NULL"

Kindly Reply Me as Soon As possible

推荐答案

在遇到这种情况时,请使用 System.DBNull ,然后它将NULL保存在数据库中.
Use System.DBNull whenever you have that case and then it will save NULL in your database.


使用
进行检查
Check using

if(String.IsNullOrEmpty(YourTextbox.Text))
{
     //Now set data as DBNull.Value
}



它将Null保存在数据库中.

另外,如果您未在insert语句中指定值,则默认情况下它将自动将其自身设置为null.



It will save Null in database.

Also if you dont specify the value in insert statement it will automatically set itself as null by default.


这篇关于C#,Sqlserver空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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