如何在linq中处理表的空列 [英] How to handle null columns of table in linq

查看:86
本文介绍了如何在linq中处理表的空列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我是linq的新手.我有一个sql表,其中有10列,其中3列设置为允许null.现在在C#中,我正在使用Linq.当用户离开空白文本框时,
我有一张桌子有3个空值允许的列.在C#代码中,我正在使用linq在对象初始化程序代码中,我正在将文本框值分配给表类的相应属性,当我将文本框留空时,它将在sql表中插入空间.但我在那里需要null.因此,如果用户未在相应的文本框中输入内容,我该如何使它为null


需要帮助或指导
在此先感谢

Hi every one

I am new to linq. i Have a sql table, having 10 columns out of which 3 are set to allow null. Now in C# i am using Linq. When the user leaves empty text boxes the
where i have a table having 3 colums with null allow. In C# code i am using linq In the object initializer code i am assigning the text box values to the corresponding property of the table class, When i left the text box blank then it inserts space in sql table. but i need null there. So how can i make it possible to have null if the user doesn''t input into the corresponding text boxes


Help or guidance is needed
Thanks in advance

推荐答案

我假设空格"是指空字符串".也许您只是想做这样的事情:
I assume by "space", you mean "empty string". Perhaps you are just looking to do something like this:
string dbField = (txtInput.Text == "" ? null : txtInput.Text);


这篇关于如何在linq中处理表的空列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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