当我使用一个SqlCommandBuilder推更新/插入/删除服务器,我需要打电话.GetUpdateCommand(),.GetInsertCommand()和.GetDeleteCommand()?
using (var adapter = new SqlDataAdapter("select * from MyTable", _connection))
using (var builder = new SqlCommandBuilder(adapter))
{
adapter.Fill(dt);
//Magic happens
builder.GetUpdateCommand(); //is this line necessary
builder.GetInsertCommand(); //is this line necessary
adapter.Update(dt);
}
Run Code Online (Sandbox Code Playgroud)
我看到有关正确程序的相互矛盾的 例子.我知道没有它可行,但我不知道它是否在幕后做了一些特别的事情.这是必要的还是货物编程?
更新:我在完全测试之前检查了答案它仍然无效.我更新了下面的代码,所以你应该只能粘贴到一个空的WinForms项目,它应该编译.
更新:我发现如果我将ComboBox上的选定项目更改为任何其他项目,它现在表现得如预期的那样(在我的代码下面,我将从test1切换到test2).由于我还没有收到任何答案,我将问题改为此.
为什么在显示我对基础数据源所做的更改之前,我必须更改组合框中的其他项?
这是一个快速测试案例.
test1为test1asdftxtBroken中的文本test2为test2asdftxtBroken中的文本test1下拉列表中的第一个项目test1test1文本框显示test1asdftest1asdtest1asd除了在幕后更改所选项目的负载并将其更改回来(这看起来像是这样的黑客)我该如何解决这个问题?
我有一个组合框数据绑定到一个BindingSource绑定List<Holder>它有Holder.Name它的显示值.我也有一个绑定的文本框,Holder.Name但如果我更改文本框中的文本,它将不会更改组合框中显示的内容.更改所选项目并更改后退将在文本框中显示更新的文本,但仍将在组合框中显示旧值.如何在组合框中更新项目?
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace Sandbox_Form
{
public class Form1 : Form
{
public Form1()
{
InitializeComponent();
lstBroken = new BindingList<Holder>();
lstBroken.Add(new Holder("test1"));
lstBroken.Add(new Holder("test2"));
bsBroken = new BindingSource(lstBroken, null);
cmbBroken.DataSource = bsBroken;
cmbBroken.DisplayMember = "Name";
cmbBroken.SelectedIndex …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个查询,该查询将通过表格并将帐户中的任何信用额应用于最旧的余额.我不知道如何在不使用游标的情况下做到这一点,我知道如果可能的话应该不惜一切代价避免使用游标,所以我来这里寻求帮助.
select * into #balances from [IDAT_AR_BALANCES] where amount > 0
select * into #credits from [IDAT_AR_BALANCES] where amount < 0
create index ba_ID on #balances (CLIENT_ID)
create index cr_ID on #credits (CLIENT_ID)
declare credit_cursor cursor for
select [CLIENT_ID], amount, cvtGUID from #credits
open credit_cursor
declare @client_id varchar(11)
declare @credit money
declare @balance money
declare @cvtGuidBalance uniqueidentifier
declare @cvtGuidCredit uniqueidentifier
fetch next from credit_cursor into @client_id, @credit, @cvtGuidCredit
while @@fetch_status = 0
begin
while(@credit < 0 and (select count(*) from …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序用于管理我们软件演示的数据库,它所做的一件事是从中央服务器获取数据库的副本并将其还原到本地SQL实例.一切都在备份部分正常工作,但在恢复时,有些人报告说他们在恢复过程中遇到以下异常.
Microsoft.SqlServer.Management.Smo.FailedOperationException: Restore failed for Server 'Computername'.
---> Microsoft.SqlServer.Management.Common.ExecutionFailureException:
An exception occurred while executing a Transact-SQL statement or batch.
---> System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
(snip)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
--- End of inner exception stack trace ---
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
(snip)
at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)
--- End of inner exception stack trace ---
at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)
at ContractFlowTool.WebInfinity2.AttachDatabase.RestoreLocal(AttachDatabaseArgs …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个C#inproc服务器sbtsv.idl(它包含在Windows 8 SDK中).我找到的几乎所有指令都会告诉您使用MIDL创建.tlb文件然后tlbimport创建代理dll.
但是,如果IDL不包含某个library部分,则不会生成任何.tlb文件,sbtsv.idl也不包含library部分.
我尝试创建自己的IDL文件,声明我想在库中创建的接口
#include "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\sbtsv.idl"
[uuid(43250D0C-BBC6-4109-BCD2-6F61F0D3B611)]
library sbtsvClientLib
{
interface ITsSbResourceNotification;
};
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行它时,MIDL我得到以下错误
Microsoft (R) 32b/64b MIDL Compiler Version 8.00.0603 Copyright (c) Microsoft Corporation. All rights reserved. Processing .\sbtsvClientLib.idl sbtsvClientLib.idl Processing C:\Program Files (x86)\Windows Kits\8.1\include\um\oaidl.idl oaidl.idl Processing C:\Program Files (x86)\Windows Kits\8.1\include\um\objidl.idl objidl.idl Processing C:\Program Files (x86)\Windows Kits\8.1\include\um\unknwn.idl unknwn.idl Processing C:\Program …
我目前正在使用Moq来帮助进行单元测试,但是遇到了一个我不知道如何解决的问题。
例如,假设我想验证CancellationToken.ThrowIfCancellationRequested()每次Upload(通话被调用一次
public UploadEngine(IUploader uploader)
{
_uploader = uploader;
}
public void PerformUpload(CancellationToken token)
{
token.ThrowIfCancellationRequested();
_uploader.Upload(token, "Foo");
token.ThrowIfCancellationRequested();
_uploader.Upload(token, "Bar");
}
Run Code Online (Sandbox Code Playgroud)
如果token是引用类型,我通常会做类似的事情
[TestMethod()]
public void PerformUploadTest()
{
var uploader = new Mock<IUploader>();
var token = new Mock<CancellationToken>();
int callCount = 0;
uploader.Setup(a => a.Upload(token.Object, It.IsAny<string>())).Callback(() => callCount++);
token.Setup(a => a.ThrowIfCancellationRequested());
var engine = new UploadEngine(uploader.Object);
engine.PerformUpload(token.Object);
token.Verify(a => a.ThrowIfCancellationRequested(), Times.Exactly(callCount));
}
Run Code Online (Sandbox Code Playgroud)
但是据我所知,最小起订量不支持值类型。什么是测试此方法的正确方法,或者没有在不CancellationToken首先将内部装箱的容器装箱之前通过Moq做我想做的事情PerformUpload(?
手动管理数据库连接时,始终打开和关闭它.有时您需要在执行某些操作之前检查连接是否具有某种状态.经典情况是在关闭连接之前检查未关闭状态.就像是
if (connection.State != ConnectionState.Closed)
connnection.Close();
Run Code Online (Sandbox Code Playgroud)
由于MSDN声明ConnectionState是枚举WITH FLAGS.这意味着连接状态可以同时具有不同的状态.可能会被打破+关闭或其他...
如果您反编译System.Data.ConnectionState枚举,您将看到
[Flags]
public enum ConnectionState
{
Closed = 0,
Open = 1,
Connecting = 2,
Executing = 4,
Fetching = 8,
Broken = 16,
}
Run Code Online (Sandbox Code Playgroud)
Closed项的值为ZERO.这意味着以下总是如此:
connection.State.HasFlag(ConnectionState.Closed)
Run Code Online (Sandbox Code Playgroud)
所以.有什么建议为什么这个枚举有Flags属性?或者(如果此枚举必须是Flags)为什么Closed项具有0值?
在过去,跟踪挂起的方法非常容易:只需转到调试器,单击“暂停”按钮并遍历堆栈跟踪即可。
但是,现在,如果问题出在异步方法中,则该方法不起作用-因为要执行的下一段代码埋在连续任务中的某个位置(从技术上讲,它甚至都没有挂起)...轻松调试任务?
UPD。
例:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private async void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
await DoHolyWar();
MessageBox.Show("Holy war complete!");
}
public static async Task DoHolyWar()
{
await DoHolyWarComplicatedDetails();
Console.WriteLine("Victory!");
}
public static async Task DoHolyWarComplicatedDetails()
{
await BurnHeretics();
}
public static Task BurnHeretics()
{
var tcs = new TaskCompletionSource<object>();
// we should have done this, but we forgot
// tcs.SetResult(null);
return tcs.Task;
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,如果启动它并单击“暂停”,则只会看到DoHolyWar方法正在挂起,但看不到确切的位置。如果您用.Wait()替换'await',然后执行相同的操作,则可以检查挂起的堆栈跟踪。通过此示例,它非常简单,但是在实际应用中,通常很难找到问题所在。特别是,桌面应用程序将在主线程上运行事件循环,因此,即使某些事情“挂起”,而您单击“暂停”,也不会知道出了什么问题。
当您有嵌套的协同例程时
void Update()
{
if(someTest)
{
StartCoroutine(Foo());
}
}
IEnumerator Foo()
{
doStuff = true;
yield return StartCoroutine(Bar());
doStuff = false;
}
IEnumerator Bar()
{
//Very important things!
}
Run Code Online (Sandbox Code Playgroud)
是StartCoroutine在yield return StartCoroutine(Bar());有必要吗?
我们是否允许这样做
void Update()
{
if(someTest)
{
StartCoroutine(Foo());
}
}
IEnumerator Foo()
{
doStuff = true;
yield return Bar();
doStuff = false;
}
IEnumerator Bar()
{
//Very important things!
}
Run Code Online (Sandbox Code Playgroud)
如果我们被允许,这是否会对程序行为/性能产生任何影响?
我维护一个库,我们的大型组织将其用于其ant配置文件。我正在尝试从junit 4后端更新到junit 5后端,同时对最终用户的干扰最小。
我遇到的主要问题是输出格式化程序。我们有一个macrodef,它接受<element name="test-formatter"/>像
<runmultipletest foo=...>
<test-formatter>
<formatter type="plain" usefile="false" />
<formatter type="xml" usefile="true" />
</test-formatter>
<runmultipletest-fileset>
<fileset refid="${junit.integration.fileset}"/>
</runmultipletest-fileset>
</runmultipletest>
Run Code Online (Sandbox Code Playgroud)
在宏定义内部
<batchtest todir="@{test.todir}" skipNonTests="@{skipNonTests}">
<test-formatter/>
<runmultipletest-fileset/>
</batchtest>
Run Code Online (Sandbox Code Playgroud)
现在我要升级到junit5。在不破坏与最终用户用于转换现有格式的现有格式的向后兼容性的情况下
<formatter type="plain" usefile="false" />
<formatter type="xml" usefile="true" />
Run Code Online (Sandbox Code Playgroud)
进入
<listener type="legacy-plain" sendSysOut="true" sendSysErr="true"/>
<listener type="legacy-xml" sendSysErr="true" sendSysOut="true" outputDir="@{test.todir}"/>
Run Code Online (Sandbox Code Playgroud)
从我的macrodef内部?我可以弄清楚XSLT可以将xml转换成我想要的格式,但是我对Ant的了解还不够,无法知道是否可以转换传入的元素然后再junitlauncher使用它。