如何在asp.net页面的表sql 2008中插入null值 [英] How to insert null value in table sql 2008 from asp.net page

查看:93
本文介绍了如何在asp.net页面的表sql 2008中插入null值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在ASP.net页面的表格中添加空值(C#代码背后)。



例子



如果我要离开一个没有输入任何值的文本框,应该为表中的相应列添加为null,我将要插入。



Textbox中的数据类型可以是整数或字符串(varchar)。如果该文本框为空,则应插入为null。



提前谢谢。

解决方案

参考类似的解决QA:在哪里 [ ^ ]和使用C#的SqlCommand参数在Sql Server2008中插入空值。 [ ^ ]


试试这个:

  string  YourValue = < span class =code-keyword> null ; 
command.Parameters.AddWithValue( @ YourValue,YourValue.DbNullIfNull());
// 如果前端为空





- Amit


参见。 。

http:// stackoverflow .com / questions / 12444115 / passing-dbnull-value-and-empty-textbox-value-to-database [ ^ ]

如何通过maskedtextbox在C#中插入空值 [ ^ ]

http://stackoverflow.com/questions/16675569/insert-null-value-in-database-with-c-sharp [< a href =http://stackoverflow.com/questions/16675569/insert-null-value-in-database-with-c-sharptarget =_ blanktitle =New Window> ^ ]

http://stackoverflow.com/questions/3913241/如何插入null-into-database [ ^ ]


I have to add null value in table from ASP.net page (C# Code behind).

Example

If i am leaving a text box with out entering any value that should be added as null for corresponding column in table which i'm going to insert.

Datatype of value in Textbox may be integer or string (varchar). If that text box is empty that should be inserted as null.

thanks in advance.

解决方案

Refer similar solved QA: here[^] and Insert null values in Sql Server2008 using SqlCommand parameters of C#.[^]


Try this:

string YourValue = null;
command.Parameters.AddWithValue("@YourValue", YourValue.DbNullIfNull());
//This will automatically insert null value if it is null in frontend




--Amit


See..
http://stackoverflow.com/questions/12444115/passing-dbnull-value-and-empty-textbox-value-to-database[^]
how to insert null value in C# through maskedtextbox[^]
http://stackoverflow.com/questions/16675569/insert-null-value-in-database-with-c-sharp[^]
http://stackoverflow.com/questions/3913241/how-to-insert-null-into-database[^]


这篇关于如何在asp.net页面的表sql 2008中插入null值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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