如何在数据库中输入null(什么都没有) [英] how can enter null (nothing) in database

查看:102
本文介绍了如何在数据库中输入null(什么都没有)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们的文本框为空,我们如何在数据库中存储null或什么都不存储

if our textbox is empty the how can we store null or nothing in database

if (MyTextBox.Text == String.Empty)
{
   // the textbox is empty
   cmd.Parameters.Add("@per_m", SqlDbType.Float).Value =    ;

}

推荐答案

尝试:
cmd.Parameters.Add("@per_m", SqlDbType.Float).Value = System.DBNull.Value;


http://msdn.microsoft.com/en-us/library/system.dbnull.aspx[^]

I hope the above information will be helpful. If you have more concerns, please let me know.


尝试
<code>
cmd.Parameters.AddWithValue("@per_m", MyTextBox.Text.Trim() == String.Empty ? DBNull.Value : (object)MyTextBox.Text);
</code>


这篇关于如何在数据库中输入null(什么都没有)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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