我正在尝试提取存储在一些格式不合理的xml列中的货币总和(没有为XML列定义的架构,我猜这是问题的一部分).每当遇到一个0为其值的节点时,我都会收到转换错误.
例:
select xml.value('sum(/List/value)', 'numeric') sum
from (select cast('<List><value>1</value><value>2</value></List>' as xml) xml) a
Run Code Online (Sandbox Code Playgroud)
给出总和3时:
select xml.value('sum(/List/value)', 'numeric') sum
from (select cast('<List><value>0</value><value>0</value></List>' as xml) xml) a
Run Code Online (Sandbox Code Playgroud)
引发错误:"将数据类型nvarchar转换为数字时出错."
在总结一个零值节点列表时,我知道如何让我的查询返回0?
我正在尝试为.NET4应用程序编写一个非常简单的自定义配置部分.我的目标是:
<configuration>
<configSections>
<section name="myServices" type="My.ConfigSection, My.Assembly" />
</configSections>
<myServices>
<add name="First" />
<add name="Second" />
</myServices>
</configuration>
Run Code Online (Sandbox Code Playgroud)
但是,ConfigurationErrorsException当我打电话时,我不断得到:'无法识别的元素'添加'' ConfigurationManager.GetSection("myServices").我已经盯着它看了一段时间,但还没弄明白我做错了什么.以下是我的代码.这是三大类:ConfigSection,MyServiceSettingsCollection和MyServiceSettings.
首先是代表整个配置部分的类.它有一个无名的默认类型集合MyServiceSettingsCollection.该IsDefaultCollection属性应该允许我从根元素直接"添加"到我的集合.
public sealed class ConfigSection : ConfigurationSection
{
private static readonly ConfigurationProperty _propMyServices;
private static readonly ConfigurationPropertyCollection _properties;
public static ConfigSection Instance { get { return _instance; } }
static ConfigSection()
{
_propMyServices = new ConfigurationProperty(
null, typeof(MyServiceSettingsCollection), null,
ConfigurationPropertyOptions.IsDefaultCollection);
_properties = new ConfigurationPropertyCollection { _propMyServices }; …Run Code Online (Sandbox Code Playgroud) 当您构建对用户和搜索引擎而言易读的URL并且您从内容自动执行此操作时,表示空格的最佳方法是什么?连字符(这是StackOverflow使用的)?强调?任何其他?SEO中的任何一个都有所不同吗?
我想保留由Quartz调度程序安排的作业历史,其中包含以下属性:"开始时间","结束时间","成功","错误".
有两个可用的接口:ITriggerListener和IJobListener(我正在使用接口的C#命名约定,因为我使用的是Quartz.NET,但可能会要求Java版本提出相同的问题).
IJobListener有JobToBeExecuted一个JobWasExecuted方法.后者提供了一个JobExecutionException让你知道什么时候出错的地方.但是,没有办法关联JobToBeExecuted和JobWasExecuted.假设我的工作运行了十分钟.我在启动t0和t0+2(让他们重叠).我接到两个电话,JobToBeExecuted并在历史表中插入两个开始时间.当两个工作完成时t1,t1+2我接到两个电话JobWasExecuted.我如何知道每次调用中要更新的数据库记录(存储结束时间及其相应的开始时间)?
ITriggerListener有另一个问题.TriggerComplete当作业失败时,无法在方法内部获得任何错误.
我如何获得所需的行为?
我有一个列的表sales(int),month(int).我想检索每个月对应的销售总额.我需要以每个月对应的12列的形式输出,其中将有一个包含每列(月)销售额的记录.
我的App.xaml文件里面一直出现一个奇怪的错误:
元素已经是另一个元素的子元素.
我的App.xaml文件如下所示:
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Celerior.Annapurna.SL.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ProvisiorResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Run Code Online (Sandbox Code Playgroud)
报告整个ResourceDictionary元素的错误(从第5行到第9行).
ProvisiorResourceDictionary.xaml包含许多样式和模板.在我看来没什么好激动的.
有谁知道什么是错的?
亲切的问候,
罗纳德威尔登伯格
我想在一些分隔符上做一个Regex.Split,但我想保留分隔符.举一个我正在尝试的例子:
"abc[s1]def[s2][s3]ghi" --> "abc", "[s1]", "def", "[s2]", "[s3]", "ghi"
Run Code Online (Sandbox Code Playgroud)
我提出的正则表达式是new Regex("\\[|\\]|\\]\\[").但是,这给了我以下内容:
"abc[s1]def[s2][s3]ghi" --> "abc", "s1", "def", "s2", "", "s3", "ghi"
Run Code Online (Sandbox Code Playgroud)
分隔符已经消失(考虑到我的正则表达式,这是有意义的).有没有办法编写正则表达式,以便保留分隔符本身?
如果我在请求中设置属性值,之后我调用session.invalidate(),属性值会发生什么?他们会在那里吗?
我试图为LINQ2SQL查询动态创建Where谓词:
...Where(SqlMethods.Like(r.Name, "%A%") ||
SqlMethods.Like(r.Name, "%B%") ||
SqlMethods.Like(r.Name, "%C%") || ...)
Run Code Online (Sandbox Code Playgroud)
A,B,C等来自某些阵列.所以我尝试了以下方法:
var roleExpression = Expression.Parameter(typeof(Role), r);
var nameExpression = Expression.Property(roleExpression, "Name");
var termExpression = Expression.Constant("%" + term[i] + "%");
var likeExpression = Expression.Call(
typeof(SqlMethods), "Like",
new[] { typeof(string), typeof(string) }, nameExpression, termExpression);
Run Code Online (Sandbox Code Playgroud)
但是,最后一行失败,并且类型为"System.Data.Linq.SqlClient.SqlMethods"的消息没有方法'Like'与提供的参数兼容.
所以我尝试了以下几行:
var likeExpression = Expression.Call(null,
typeof(SqlMethods).GetMethod("Like", new[] { typeof(string), typeof(string) }),
nameExpression, searchTermExpression)
Run Code Online (Sandbox Code Playgroud)
这有效.但是,我不明白这两行之间的区别.在我看来,他们应该提供相同的结果.
有人能解释一下吗?
亲切的问候,
罗纳德威尔登伯格
在F#中,我知道如何使用Async.AwaitEvent以下方法异步等待一个事件:
let test = async {
let! move = Async.AwaitEvent(form.MouseMove)
...handle move... }
Run Code Online (Sandbox Code Playgroud)
假设我想要等待MouseMove或者KeyDown事件.我想要这样的东西:
let! moveOrKeyDown = Async.AwaitEvent(form.MouseMove, form.KeyDown)
Run Code Online (Sandbox Code Playgroud)
这个功能不存在,但有另一种方法吗?