本文介绍了如果database列为null,则用string替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





i只想问一下如何使用sql server在C#中编写以下场景:



1.我正在编写一个页面,反映表单是否已经提交。我有[name]列和[date submitted]列。



2.我想替换[date submitted]列中的数据。如果[提交日期]有条目,我希望将其反映为已提交,如果[提交日期]为空,则无法提交。



3. [名称]和[提交日期]来自不同的数据库:mydb.name和project.dateSubmitted



4.它将反映到一个gridview



5.在gridview内部,会有一列按钮。如果[提交日期]为空,则该按钮将被禁用。如果[提交日期]有条目,则启用。



感谢



i just want to ask how to code in C# using sql server the following scenario:

1. I am coding a page that reflects if a form is already submitted or not. i have [name] column and [date submitted] column.

2. I want to replace the data inside the [date submitted] column. I want to reflect it as ALREADY SUBMITTED if [date submitted] has entry and NOT YET SUBMITTED if [date submitted] is null.

3. [name] and [date submitted] comes from different databases: mydb.name and project.dateSubmitted

4. it will reflect into just one gridview

5. inside gridview, there will be a column for buttons. if [date submitted] is null, the button will be disabled. enabled if [date submitted] has entry.

thanks

推荐答案

//dr is datareader
if ( dr[0][0] is DBNull )
{
//Handle null here
}


SELECT NAME,
CASE WHEN dateSubmitted IS NULL THEN 'NOT YET SUBMITTED'
     ELSE 'ALREADY SUBMITTED' END 'STATUS'
FROM MYTABLE


这篇关于如果database列为null,则用string替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 07:03