小编Kja*_*tan的帖子

如何在MSSQL中连接字符串和GETDATE()

我需要插入一个应该包含日期的字符串(注释).我需要的基本上是以下简单的操作:

INSERT INTO [Table_1]
           ([textColumn])
     VALUES
           ('Date: ' + GETDATE())
GO
Run Code Online (Sandbox Code Playgroud)

但是,这会返回以下错误:从字符串转换日期和/或时间时转换失败.

任何快速修复?

sql-server string concatenation getdate

6
推荐指数
2
解决办法
4万
查看次数

Visual Studio参数化单元测试就像java一样

在java测试环境中我可以使用参数化单元测试,如下面的代码,

@RunWith(value = Parameterized.class)
public class JunitTest6 {

    private int number;

    public JunitTest6(int number) {
        this.number = number;
    }

    @Parameters
    public static Collection<Object[]> data() {
        Object[][] data = new Object[][] { { 1 }, { 2 }, { 3 }, { 4 } };
        return Arrays.asList(data);
    }

    @Test
    public void pushTest() {
        System.out.println("Parameterized Number is : " + number);
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我怎么能在visual studio单元测试项目中做到这一点.我找不到参数化属性或这样的任何样本.

c# java tdd junit unit-testing

6
推荐指数
1
解决办法
5742
查看次数

HttpWebRequest突然停止工作,几个请求后没有收到响应

我正在使用WPF .net 4.0应用程序.我有一个搜索栏.对于每个搜索令牌,我需要对8个单独的URL执行8个http请求以获取搜索结果.一旦用户停止在搜索栏中输入,我会在400毫秒后向服务器发送8个请求.搜索6到7个搜索令牌的结果非常好.但在那之后突然HttpWebRequest停止了默默工作.没有例外,没有收到任何回复.我正在使用Windows 7,我也禁用了防火墙.我不知道后续的http请求丢失在哪里.

任何人都可以向我展示灯来解决这个问题吗?

下面是我的HttpWebRequest调用代码.

public static void SendReq(string url)
{
    // Create a new HttpWebRequest object.
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

    request.ContentType = "application/x-www-form-urlencoded";
    request.Proxy = new WebProxy("192.168.1.1", 8000);

    // Set the Method property to 'POST' to post data to the URI.
    request.Method = "POST";

    // start the asynchronous operation
    request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request);

}

private static void GetRequestStreamCallback(IAsyncResult asynchronousResult)
{
    HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;

    // End the operation
    Stream postStream = request.EndGetRequestStream(asynchronousResult);

    string postData = this.PostData;

    // Convert the …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf httpwebresponse

6
推荐指数
2
解决办法
3266
查看次数

RhinoMocks - 当一个方法被调用n次时,如何在n-k调用中测试它的参数

我有一个方法,它恰好调用另一种方法4次,每次使用不同的参数.我想写了4个不同的单元测试用例来检查方法,每个调用都有一个特定的值.

以下是我的方法的外观:

public void MainMethod()
{
    IServiceProvider serviceProvider = GetServiceProvider();

    string value1 = GetValueFromStorage("SomeArg1");
    // Call AnotherMethod
    serviceProvider.AnotherMethod(value1);

    string value2 = GetValueFromStorage("SomeArg2");
    // Call AnotherMethod
    serviceProvider.AnotherMethod(value2);

    string value3 = GetValueFromStorage("SomeArg3");
    // Call AnotherMethod
    serviceProvider.AnotherMethod(value3);

    string value4 = GetValueFromStorage("SomeArg4");
    // Call AnotherMethod
    serviceProvider.AnotherMethod(value4);
}
Run Code Online (Sandbox Code Playgroud)

这是我的测试方法:

public void TestMainMethod()
{
    // Stub storage
    IDataStorage dataStorage = MockRepository.GenerateStub<IDataStorage>();

    // Stub serviceProvider
    IServiceProvider dataStorage = 
         MockRepository.GenerateStub<IServiceProvider>();

    // stub for SomeArg1
    dataStorage.Stub(x => x.GetValueFromStorage(null)
                           .IgnoreArguments().Return("Value1"))
                           .Repeat.Once();

    // stub for SomeArg2
    dataStorage.Stub(x => x.GetValueFromStorage(null)
                           .IgnoreArguments().Return("Value2"))
                           .Repeat.Once(); …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing rhino-mocks

6
推荐指数
1
解决办法
1004
查看次数

如何使用PowerShell远程确定存储类型(SAN/NAS /本地磁盘)?

我必须在我们的环境中收集每个服务器的附加存储类型:数百个W2K3/W2K8服务器.

脚本对于确定附加存储是否是SAN / SAN mirrored / NAS / local这些存储或其组合非常有用.问题是我还没有找到任何好的解决方案.

我正在考虑一个脚本,我能想到的最好的东西会做如下的事情:

  • 如果服务器使用SAN,则始终安装Veritas Storage Foundation,因此我将使用gwmi win32_product进行搜索.这非常慢,如果存储是SAN或SAN镜像,则不提供信息.
  • 如果连接的存储是NAS,必须有一个ISCSI目标IP,我会以某种方式搜索它.

我真的不认为这些方法是可以接受的.你能帮我找一个更好的方法来确定附加的存储类型吗?

非常感谢你

powershell storage san nas

6
推荐指数
1
解决办法
2万
查看次数

如何控制Datagridview中的SendKeys.Send{"tab"}属性?

我在 datagridview 单元格输入事件中编写代码为

private void dgvGoodsRecpt_CellEnter(object sender, DataGridViewCellEventArgs e)
{
    if (dgvGoodsRecpt.CurrentRow.Cells[e.ColumnIndex].ReadOnly)
    {
        SendKeys.Send("{tab}");
    }
}
Run Code Online (Sandbox Code Playgroud)

如果当前单元格是 ,此代码会将选项卡发送到下一个单元格ReadOnly true

它运行良好,但我的问题是我的 datagridview 最后一列是readonly true,下一个控件是txtAmount1.TexttxtAmount2.Text

当我继续按 Tab 键时,焦点将变为txtAmount2.Text。但紧邻 datagridview 的是txtAmount1.Text. 焦点将转到 datagridview 之后的 imidiate 控件的下一个控件。焦点应该集中在txtAmount1.Text控件上。我应该怎么办?请帮我。

c# datagridview sendkeys

6
推荐指数
1
解决办法
3万
查看次数

得到错误"位置0没有行"

请帮我解决这个问题...我收到的错误是"0号位没有行","索引超出范围的例外是用户代码无法解决的"

以下是我的代码

protected void Page_Load(object sender, EventArgs e)
{
    MTMSService obj = new MTMSService();
    DBAccess db = new DBAccess();
    {
        MTMSDTO objc = new MTMSDTO();
        {
            objc.TaskID = Convert.ToInt32(Session["TaskID"]);
            DataSet rep = obj.GetReports(objc);
            DataView Rprts = new DataView();
            Rprts.Table = rep.Tables[0];

            LblTaskID.Text = rep.Tables[0].Rows[0]["TaskID"].ToString();
            LblTaskName.Text = rep.Tables[1].Rows[0]["TaskName"].ToString();
            LblDueDate.Text = rep.Tables[2].Rows[0]["DueDate"].ToString();
            LblDescription.Text = rep.Tables[3].Rows[0]["Description"].ToString();
            LblAssignBy.Text = rep.Tables[4].Rows[0]["AssignBy"].ToString();
            LblStatus.Text = rep.Tables[5].Rows[0]["Status"].ToString();
            LblPercentageComplete.Text = 
                    rep.Tables[6].Rows[0]["PercentageComplete"].ToString();

            LblTaskName.Visible = true;
            LblAssignBy.Visible = true;
            LblDescription.Visible = true;
            LblDueDate.Visible = true;
            LblStatus.Visible = true;
            LblPercentageComplete.Visible = true; …
Run Code Online (Sandbox Code Playgroud)

c# asp.net exception

6
推荐指数
1
解决办法
4万
查看次数

如何以编程方式单击ApplicationBarIconButton?

这就是问题所在.我的测试框架中有以下代码变体(假设appBarButton是ApplicationBarIconButton):

var bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic;
var method = typeof(ApplicationBarIconButton)
             .GetMethod("ClickEvent", bindingFlags);

if (method != null)
{
    method.Invoke(appBarButton, null);
}
Run Code Online (Sandbox Code Playgroud)

要么

IInvokeProvider invokableButton;
var isInvokable = (invokableButton = appBarButton as IInvokeProvider) != null;
if (isInvokable)
{
    invokableButton.Invoke();
}
Run Code Online (Sandbox Code Playgroud)

两件都不起作用.所以我想找到一些以编程方式单击ApplicationBarIconButton的变通方法.有帮助吗?

c# appbar windows-phone windows-phone-8

6
推荐指数
1
解决办法
450
查看次数

.netcore / .netstandard 项目之间的 Resharper 引用错误

我在 Visual Studio 中有两个项目,其中第一个中的类指的是第二个中的类。第一个项目是一个 .netcore 应用程序,在它的项目文件中包含以下内容:

<TargetFramework>netcoreapp2.0</TargetFramework>
Run Code Online (Sandbox Code Playgroud)

第二个项目有多个目标框架:

<TargetFrameworks>netstandard2.0;net461;net462</TargetFrameworks>
Run Code Online (Sandbox Code Playgroud)

两个项目都可以编译并正常工作,但是位于第二个项目中的类在第一个项目的代码中显示为红色,好像存在引用错误。对于上下文,这是一个通用示例:

在此处输入图片说明

被弄脏的红色部分是另一个项目中定义的类。我可以导航到它(使用F12/“转到定义”或ctrl+单击),但是当我将光标悬停在红色文本上方时,会显示

无法解析符号“MyClassName”

所以要绝对清楚:一切仍然有效- 只是 Resharper 错误地报告了她的参考错误,这让我感到困扰。

我怎么知道 resharper 导致了这个?因为如果我禁用 Resharper(工具 -> 选项,搜索 resharper 并单击“暂停”),错误就会消失:

在此处输入图片说明

再次启用 Reshaper 会导致错误立即返回。

我怀疑这与项目的类型(即他们的目标框架)有关,但我一直无法准确地弄清楚。

关于如何摆脱这些错误的任何想法?

.net c# resharper visual-studio .net-core

6
推荐指数
1
解决办法
390
查看次数

如何链接两个希望您提供流的C#API?

我正在使用两个C#流API,其中一个是数据源,另一个是数据接收器.

两个API都没有实际公开流对象; 两者都希望您将流传递给它们,并且它们处理流中的写入/读取.

有没有办法将这些API链接在一起,以便源的输出流入接收器,而不必在MemoryStream中缓冲整个源?这是一个非常敏感的RAM应用程序.

这是一个使用我正在尝试避免的MemoryStream方法的示例,因为它在将整个流缓存到RAM之前将其缓存在RAM中:

using (var buffer = new MemoryStream())
using (var transferUtil = new TransferUtility(s3client))
{
    // This destructor finishes the file and transferUtil closes 
    // the stream, so we need this weird using nesting to keep everyone happy.
    using (var parquetWriter = new ParquetWriter(schema, buffer)) 
        using (var rowGroupWriter = parquetWriter.CreateRowGroup())
        {
            rowGroupWriter.WriteColumn(...);
            ...
        }
    transferUtil.Upload(buffer, _bucketName, _key.Replace(".gz", "") + ".parquet");
}
Run Code Online (Sandbox Code Playgroud)

c# stream amazon-s3 parquet .net-core

6
推荐指数
1
解决办法
384
查看次数