小编Pan*_*vos的帖子

重复的连接字符串错误

我在服务器中部署了一个网站.有一天它抛出一个错误,说connection string已经添加了名称.我检查了web.config文件,它只有一个名称.我从配置中删除了该条目.现在该网站运行良好,从数据库中获取数据.

注意:当我更改配置文件的名称时,它显示错误.

我认为,问题是 - connectionstring部分缓存在内存中.是这样吗?我们如何克服这种不受欢迎的行为?

在源代码中配置文件

发布配置

<system.web>
 <compilation xdt:Transform="RemoveAttributes(debug)" />

</system.web>
Run Code Online (Sandbox Code Playgroud)

调试配置

<system.web>

</system.web>
Run Code Online (Sandbox Code Playgroud)

参考文献:

  1. 在我发布的Web配置中出现不需要的连接字符串问题
  2. .NET 2.0 App.Config连接字符串包含不需要的SQLExpress默认值

c# asp.net connection-string config xdt-transform

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

Linq/Lambda代码在vb中工作但不在c#中工作

以下适用于VB ..

Dim q = allValues.GroupBy(Function(u) u.R).Select(Function(grp) grp).OrderByDescending(Function(a) a.Count).ToList
Run Code Online (Sandbox Code Playgroud)

但不是在C#..

dynamic q = allValues.GroupBy(u => u.R).Select(grp => grp).OrderByDescending(a => a.Count).ToList;
Run Code Online (Sandbox Code Playgroud)

"allValues"是各种像素的颜色列表.我正在尝试将颜色R值分组并按计数降序排序以找到最常用的颜色.

我是C#和Lambda的菜鸟.这也是我在网站上的第一篇文章.谢谢你的任何邀请!

c# vb.net

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

将 Entity Framework Code First 与 mysql 一起使用时强制 engine=innodb

我使用实体框架 6 和 msyql 数据库创建了一个新的 .NET MVC 5 Web 应用程序。我首先使用代码/模型。数据库服务器有一个默认的存储引擎 MyISAM,但我希望 EF 创建的表是 InnoDb。有谁知道是否有办法指定 EF 将在CREATE TABLE语句中使用的存储引擎?

mysql asp.net-mvc entity-framework entity-framework-6 entity-framework-migrations

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

从datepart更正周数

代码返回:

set datefirst 1
select datepart(wk,'2016-01-01')  - 1
Run Code Online (Sandbox Code Playgroud)

set datefirst 1
select datepart(wk,'2015-12-31')
Run Code Online (Sandbox Code Playgroud)

return..53:/

但事实上 - 这是同一周.本周有更多的日子属于2015年,所以对于这个特定周的任何日期,它应该是"53"或"1"(相同的值).如果没有建立专门的程序来分析日期和调整返回值,是否可以实现这一目标?

我使用SQL Server 2005

sql-server week-number datepart

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

为什么我不能在函数中实例化一个对象

基本上我有一个NodeTree类:

public class NodeTree
{
    public NodeTree(int value, NodeTree left, NodeTree right)
    {
        Value = value;
        Right = right;
        Left = left;
    }

    public int Value { get; set; }
    public NodeTree Right { get; set; }
    public NodeTree Left { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

在我的主要部分,我想做点什么

NodeTree root = null;
Algo.InsertValueIt(root, 8);
Run Code Online (Sandbox Code Playgroud)

InsertValueIt()是我的静态类Algo中的一个方法,它执行:

 public static void InsertValueIt(NodeTree root, int val)
    {
        var newNode = new NodeTree(val, null, null);
        if (root == null)
        {
            root = newNode;
        }
    }
Run Code Online (Sandbox Code Playgroud)

在我的方法中,一切都按预期工作,但回到我的主要,我的对象根仍然是空的.我感到困惑的原因是我给我的方法一个引用,所以它应该将地址的值修改为我分配的新空间.

我想我可以通过返回一个NodeTree来解决我的问题,但有没有办法用void返回类型做到这一点?

c#

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

C#-log4Net不写入控制台

log4Net通过调试或错误模式仅写入文件,而不写入控制台。

甚至我在配置文件中添加了文件和控制台appanders。

这是我的配置文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
  </configSections>
  <log4net>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="log/SBT.UI.log"/>
      <encoding value="utf-8"/>
      <appendToFile value="true"/>
      <rollingStyle value="Composite"/>
      <datePattern value="yyyyMMdd"/>
      <maxSizeRollBackups value="10"/>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date{dd/MM/yyyy HH:mm:ss}, %message%newline"/>
      </layout>
    </appender>
     <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
      <param name="Threshold" value="DEBUG" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
      </layout>
    </appender>
    <root>
      <level value="DEBUG"/>
      <appender-ref ref="RollingLogFileAppender"/>
      <appender-ref ref="ConsoleAppender"/>
    </root>
  </log4net>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)

c# log4net visual-studio

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

如何在mvc中使用当前时间将字符串转换为DateTime对象

string date = "23/12/2017";

DateTime dt = DateTime.ParseExact(
  date, 
 "dd/MM/yyyy hh:mm:ss tt", 
  CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)

dt它给了我12/23/2017 12:00:00 AM

什么办法我必须用这个字符串转换为dd/mm/yyyy与当前的时间,因为如果我在运行此代码03:20 PM,我想"23/12/2017 03:20:00 PM"在我的dt对象

我有一个 ASP.NET MVC 操作,它接受一个日期作为字符串并将其保存到一个数据库表中,在一个类型为 DATE 的字段中。

我正在保存我的 dt 对象。我想将我的日期保存为 DD/MM/YYYY,因此我不需要更改其顺序。现在 dt 对象采用 MM/DD/YYYY 格式。所以当我浏览我的表格数据时,它会以 MM/DD/YYYY 顺序显示数据(日期)。我想将我的 dt 对象订购为 DD/MM/YYYY 以便它在表格中保存为 DD/MM/YYYY 所以每当我从我的表格中获得价值时,我都不必更改订单

/// asp.net Entities link to create connection with DataBase
    private DatabaseEntities db = new DatabaseEntities(); 

//// Method to Save date in database
    public ActionResult SaveDate(string date){
        var …
Run Code Online (Sandbox Code Playgroud)

c# asp.net datetime date

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

Dapper - "必须声明标量变量@VersionId"

我正在尝试使用Dapper对我本地计算机上可用的数据库执行一些简单查询.

大多数查询工作正常,但是当我尝试将对象插入数据库中的相应表时,我得到了一个SqlException.我有一个类似的插入方法,首先实例化方法体内的对象并将其插入数据库,该方法工作正常.但是这个没有.更具体地说,这是异常的回应:

System.Data.SqlClient.SqlException: 'Must declare the scalar variable "@VersionId".'
Run Code Online (Sandbox Code Playgroud)

以下是产生异常的调用代码:

public int CreateNewSchema(Schema schema)
        {
            string sql = "INSERT INTO Schemas(VersionId, Created, Updated, SchemaData) " +
                         " values (@VersionId, @Created, @Updated, @SchemaData);";

            var affectedRows = _connection.Execute(sql, new{schema});
            return affectedRows;
        }
Run Code Online (Sandbox Code Playgroud)

我的数据库中相应的Schema表具有以下设计.

Schema 
ID             int
VersionID      nvarchar(max)
Created        datetime2(7)
Updated        datetime2(7)
SchemaData     nvarchar(max)
Run Code Online (Sandbox Code Playgroud)

最后,我试图在此表中插入的POCO对象定义如下:

public class Schema
    {
        public int ID { get; set; }
        public string VersionId { get; set; }
        public DateTime Created { get; set; } …
Run Code Online (Sandbox Code Playgroud)

c# sql asp.net dapper

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

SQL 累积总和直到标志值并重置总和

我仍在学习 SQL,并且正在尝试找出我无法解决的问题。所以我的问题是我正在尝试选择一个表(比如费用),按日期排序,在表中我有一个名为 Charged 的​​列,我想添加要累积的费用(这部分我想出了)。但是,在那之后,我还有另一列将充当名为 PayOut 的标志。当 PayOut 值为 1 时,我希望 Charged(SumValue) 的总和重置为零。我该怎么做?这是我尝试过的以及我得到的当前输出以及我想要的输出。注意:我看到一些使用 CTE 的帖子,但场景不同,而且更复杂。

select ex.date, 
       ex.Charged,
       (case when(ex.PayOut=1) then 0 
             else sum(ex.Charged) over (order by ex.date)end) as SumValue, 
      ex.PayOut
from Expense ex 
order by ex.date asc
Run Code Online (Sandbox Code Playgroud)

数据看起来像这样

Date       Charged   PayOut
01/10/2018   10        0
01/20/2018   5         0
01/30/2018   3         0
02/01/2018   0         1
02/11/2018   12        0
02/21/2018   15        0
Run Code Online (Sandbox Code Playgroud)

我得到的输出

Date       Charged   PayOut  SumValue
01/10/2018   10        0        10
01/20/2018   5         0        15
01/30/2018   3         0        18
02/01/2018   0         1        0 …
Run Code Online (Sandbox Code Playgroud)

sql sql-server

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

C# Sql ADO.Net DataColumn 添加可为空的 Guid 列时出错

我正在尝试从 C# 调用 sql 存储过程。我有以下代码来创建 DataColumn。但是在添加可为空的 Guid 和 DateTime 类型时创建 DataTable 时出现错误。

DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[]
        {
            new DataColumn(nameof(LearnerEntity.FirstName), typeof(string)),
            new DataColumn(nameof(LearnerEntity.DateOfBirth), typeof(DateTime?)),
            new DataColumn(nameof(LearnerEmployerEntity.SectorId), typeof(Guid?)),
            new DataColumn(nameof(LearnerEntity.EPortfolioId), typeof(int?))
        });
        dt.Rows.Add(
            learnerEntity.FirstName,
            learnerEntity.DateOfBirth ?? SqlDateTime.Null,
            learnerEntity.Employer?.SectorId ?? SqlGuid.Null.Value,
            learnerEntity.EPortfolioId ?? SqlInt32.Null.Value); 
Run Code Online (Sandbox Code Playgroud)

错误是:

DataSet does not support System.Nullable<>. 
Run Code Online (Sandbox Code Playgroud)

谁能帮助我我在这里做错了什么?

我正在尝试以下操作:

DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[]
        {
            new DataColumn(nameof(LearnerEntity.FirstName), typeof(string)),
            new DataColumn(nameof(LearnerEntity.DateOfBirth), Nullable.GetUnderlyingType(typeof(LearnerEmployerEntity).GetProperty("DateOfBirth").PropertyType)),
            new DataColumn(nameof(LearnerEmployerEntity.SectorId), Nullable.GetUnderlyingType(typeof(LearnerEmployerEntity).GetProperty("SectorId").PropertyType)),
            new DataColumn(nameof(LearnerEntity.EPortfolioId), Nullable.GetUnderlyingType(typeof(LearnerEmployerEntity).GetProperty("EPortfolioId").PropertyType))
        });
        dt.Rows.Add(
            learnerEntity.FirstName,
            learnerEntity.DateOfBirth ?? SqlDateTime.Null,
            learnerEntity.Employer?.SectorId ?? …
Run Code Online (Sandbox Code Playgroud)

c# ado.net

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