如何在switch case语句中检查控件类型?
Private void CheckControl(Control ctl)
{
switch (ctl) {
case TextBox: MessageBox.Show("This is My TextBox");
break;
case Label: MessageBox.Show("This is My Label");
break;
}
}
Run Code Online (Sandbox Code Playgroud)
以下是上述声明中的错误:
"文本框"是一种类型,在给定的上下文中无效
想要准备没有空列的 json。
这是详细示例
我的表
=================
id , Name
=================
1 , Ali
2 ,
3 , jhon
=================
Run Code Online (Sandbox Code Playgroud)
JSON 的 SQL 语句
(SELECT [Id],[Name] FROM My_Table)
FOR JSON PATH
Run Code Online (Sandbox Code Playgroud)
SQL 结果:
[{
"Id": 1,
"Name": "Ali"
}, {
"Id": 2,
"Name": ""
}, {
"Id": 3,
"Name": "Jhon"
}]
Run Code Online (Sandbox Code Playgroud)
但我想排除没有值的元素,例如以下结果中的 No "Name":"" Element:
[{
"Id": 1,
"Name": "Ali"
}, {
"Id": 2,
}, {
"Id": 3,
"Name": "Jhon"
}]
Run Code Online (Sandbox Code Playgroud)
编辑: 请注意,我可以应用 CASE 或 UDF 将空值转换为 null,并且 null 值可能会从 json 中删除,但它会降低大量记录的整体性能,因此寻找明智的解决方案。
如果数字为零,想要格式化我的数字值,那么应该显示破折号(“-”)而不是零。格式或 MaskInput 是什么?
例如:
========================================
MyNumberFormatted MyNumberNoFormat
========================================
- 0
5 5
- 0
1 1
========================================
Run Code Online (Sandbox Code Playgroud)