如何从前面传递空值 [英] How to pass null values from front
本文介绍了如何从前面传递空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您需要帮助.
从前端,如果我的数据类型为"int","Datetime",如何将空值传递给数据库.
Hi need a help.
From front end, how can i pass null values to the database if my datatype is ''int'', ''Datetime''.
推荐答案
您需要修改SP的输入参数,或者需要从前端发送空值.我建议您使用sp的Modify输入参数为null.试试这个:
SQL:
In this case either you need to modify the input parameters of the SP or you need to send null values from front-end. I would suggest you to use modify input parameter of the sp as null. Try this:
SQL:
CREATE PROCEDURE spTest
@Param1 INT = NULL,
@Param2 DATETIME = NULL
AS
BEGIN
-- Your code goes here
END
如果用户输入或选择了值,则仅将参数添加到命令对象.
前端:
If user has entered or selected the values then only add the parameters to the command object.
Front-end:
if (textbox1.Text.Trim() != "")
{
cmd.Parameters.Add("@Param1", Convert.ToInt32(textbox1.Text));
}
if (datetimepicker.SelectedDate.HasValue)
{
cmd.Parameters.Add("@Param2", datetimepicker.SelectedDate);
}
祝一切顺利.
--Amit
All the best.
--Amit
检查类似的内容
将null从c#发送到sql位类型 [ ^ ]
最好的问候
M.Mitwalli
Hi ,
Check this similar
send null to sql bit type from c#[^]
Best Regards
M.Mitwalli
嗨....
为了允许空值,必须为变量使用数据类型"int?"而不是"int".然后,您可以为该变量设置null值并将其传递给数据库.
hi....
For allowing null values, u must use datatype ''int?'' instead of ''int'' for a variable. Then u can set null value for that variable and pass it to database.
这篇关于如何从前面传递空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文