当我发布我的项目并在服务器上运行它时,它工作.EPPlus找到了所有4个工作表,通过它们进行迭代,并将我的数据上传到SQL.
但是当我通过我的浏览器或我的同事浏览器运行它时,它会显示0个工作表.
知道为什么会这样吗?那时代码并不多,但是这部分是:
using (ExcelPackage package = new ExcelPackage(new FileInfo(strFile)))
{
if (package.Workbook.Worksheets.Count <= 0)
strError = "Your Excel file does not contain any work sheets";
else
{
foreach (ExcelWorksheet worksheet in package.Workbook.Worksheets)
{
Run Code Online (Sandbox Code Playgroud) 我有一个CSV文件,每行看起来类似于:
EASTTEXAS,NULL,BELLVILLE AREA,NULL,BELLVILLE AREA,RGP,NULL,NULL,0,NULL,NULL,NULL,1,1,PM,PM Settings,NULL,NULL
Run Code Online (Sandbox Code Playgroud)
我在BULK INSERT上找不到关于如何处理NULL值的任何示例,所以我认为没问题.
当我尝试运行BULK INSERT时,它给了我这个错误:
消息4864,级别16,状态1,行28第1行第12列(ClassificationPK)的批量装入数据转换错误(指定代码页的类型不匹配或无效字符).
这是我的表,不是:
CREATE TABLE #Assets
(
ParentID VARCHAR(255) NULL,
ClassificationID VARCHAR(255) NULL,
AssetID VARCHAR(255) NULL,
AssetType VARCHAR(255) NULL,
AssetName VARCHAR(255) NULL,
RepairCenterID VARCHAR(255) NULL,
LaborID VARCHAR(255) NULL,
Owner VARCHAR(255) NULL,
IsLocation VARCHAR(255) NULL,
AssetTypeDesc VARCHAR(255) NULL,
ClassificationName VARCHAR(255) NULL,
ClassificationPK INT NULL,
IsUp BIT NULL,
RequesterCanView BIT NULL,
PMCycleStartBy VARCHAR(255) NULL,
PMCycleStartByDesc VARCHAR(255) NULL,
PMCycleStartDate DATETIME NULL,
PMCounter INT NULL,
ParentPK INT NULL,
ParentName VARCHAR(255) NULL,
AssetPK INT NULL,
RepairCenterPK INT …Run Code Online (Sandbox Code Playgroud) 我首先使用数据库,我有一个switch看起来像这样的语句:
switch (site)
{
case Site.One:
using (OneContext one = new OneContext())
return one.OrganizationObjects.SingleOrDefault(x => x.u_Name == orgName)?.g_org_id;
case Site.Two:
using (TwoContext two = new TwoContext())
return two.OrganizationObjects.SingleOrDefault(x => x.u_Name == orgName)?.g_org_id;
default:
throw new NotImplementedException();
}
Run Code Online (Sandbox Code Playgroud)
两个数据库非常相似,几乎都有相同的模型.
如果我删除"两个"EDMX文件并注释掉条件,那么OneContext可以正常工作.
如果我将TwoContext EDMX文件添加到项目并再次运行代码,则"OneContext"代码在尝试查询时失败OrganizationObjects.
我确保每个上下文都使用正确的连接字符串,但仍会出现此错误:
当我调用logoff时,它可以工作.但是关机和重启不起作用.一切都很好看.我查看了SO上的其他示例以及其他地方和代码在大多数地方看起来非常统一.所以我认为它可能不是代码.
我正在以管理员身份运行,我在没有强制标志的情况下尝试了它.
public void ShutdownComputer(ShutdownType type, bool force)
{
switch (type)
{
case ShutdownType.Shutdown:
ExitWindowsEx(ExitWindows.ShutDown | (force ? ExitWindows.Force : ExitWindows.ForceIfHung), ShutdownReason.MajorOther | ShutdownReason.MinorOther | ShutdownReason.FlagPlanned);
break;
case ShutdownType.Restart:
ExitWindowsEx(ExitWindows.Reboot | (force ? ExitWindows.Force : ExitWindows.ForceIfHung), ShutdownReason.MajorOther | ShutdownReason.MinorOther | ShutdownReason.FlagPlanned);
break;
case ShutdownType.Logoff:
ExitWindowsEx(ExitWindows.LogOff | (force ? ExitWindows.Force : ExitWindows.ForceIfHung), ShutdownReason.MajorOther | ShutdownReason.MinorOther | ShutdownReason.FlagPlanned);
break;
}
}
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ExitWindowsEx(ExitWindows uFlags, ShutdownReason dwReason);
[Flags]
public enum ExitWindows : uint …Run Code Online (Sandbox Code Playgroud) 我有一个绑定到输入字段的属性:
<input id="name" asp-for="ContactName" name="ContactName" placeholder="Name" type="text" style="width: 200px !important;" autofocus>
[BindProperty]
public string ContactName { get; set; }
Run Code Online (Sandbox Code Playgroud)
当我发布时,我尝试ContactName通过将其设置为 NULL 或 string.Empty 来清除该属性,但它不起作用。
清除此字段的正确方法是什么?
我也无法看到设计师.它只向我展示了现有项目的XAML.

有想法该怎么解决这个吗?
我有一个存储过程,它使用一个简单的UPDATE,并传递一些变量.但是当我们的变量不为null时,我不想更新这些字段.这基本上就是我的陈述.
UPDATE myTable
SET myColumn = @myColumn,
mColumn1 = @myColumn1
WHERE myColumn2 = @myColumn2
Run Code Online (Sandbox Code Playgroud)
无论如何在SET中应用一些条件逻辑?我有大约10个需要检查的字段,所以我不希望每个字段或类似的事情进行更新.
有任何想法吗?
我有一个简单的查询,其中 WHERE 子句如下所示:
where EF.Functions.Like(header.OrderNumber, numbers[0]) || EF.Functions.Like(header.CustomerPoNumber, numbers[0])
Run Code Online (Sandbox Code Playgroud)
我专门使用EF.Functions.Like,因为我希望用户能够%根据需要插入。但我正在努力弄清楚如何才能实现这种动态。正如您从 中看到的numbers[0],我目前正在对第一个要测试的项目进行硬编码。但实际上,我需要循环遍历这些项目,并在OR将它们添加到WHERE子句中时对每个项目执行一个操作。
我之前已经用System.Linq.Dynamic.Core. 我创建了一个动态WHERE语句并使用.Contains. 但问题是.Contains在创建查询时强制使用双通配符。我需要能够让用户选择何时包含它。
关于如何实现这一目标有什么想法吗?
我正在创建一个弹出菜单,一个ToggleButton和一个Popup控件.所有这些都包含在画布中.以下图片位于我的应用程序的右下角.我将我的Canvas设置为在Index 1列中,拉伸2列,并在第二行到底行.

灰色图像只是一个占位符.从下面的XAML中,您可以看到我已将所有内容设置为拉伸.Canvas延伸,但没有别的.注释掉StackPanel和/或Label什么都不做.所以我确信这两者都不是原因.ToggleButton没有拉伸到Canvas的大小.

我做了截图,所以我可以更好地突出显示相关部分.但如果我需要粘贴代码,我可以.
编辑
更新了XAML:
<Border BorderBrush="Green" BorderThickness="1" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid Name="ToggleButtonCanvas" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<ToggleButton x:Name="btnPluginMenu" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<ToggleButton.Template>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="bdr" BorderThickness="0">
<Border.Background>
<ImageBrush ImageSource="< omitted >" Stretch="Fill" TileMode="None" />
</Border.Background>
<ContentPresenter VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="8,6,8,6" ContentSource="Content" />
</Border>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
<Label Canvas.Left="10" Canvas.Top="10" Content="Menu" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
</StackPanel>
<Popup Placement="Relative" HorizontalOffset="-120" VerticalOffset="-130" PlacementTarget="{Binding ElementName=btnPluginMenu}" IsOpen="{Binding ElementName=btnPluginMenu, Path=IsChecked}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" PopupAnimation="Scroll">
<Grid Background="Gray">
<Grid.BitmapEffect> …Run Code Online (Sandbox Code Playgroud) 在开发中工作得很好,但是当我发布到服务器时会搞砸.这就是href的设置方式:"/tools/pages/page.aspx".但我的Web应用程序是IIS中默认站点的应用程序.所以主URL是这样的:http://domain/mysite/.因此,当我使用"/"转到根目录时,它会转到域而不是mysite.
我期待这个:http://domain/mysite/tools/pages/page.aspx,但我得到的是:http://domain/tools/pages/page.aspx
有关如何解决此问题的任何想法?
这是我的扩展方法:
public static void SetThreadSafeProperty<T>(this System.Windows.FrameworkElement control, Expression<Func<T>> property, T value)
{
if (control.Dispatcher.CheckAccess())
{
var del = new SetThreadSafePropertyDelegate<T>(SetThreadSafeProperty);
control.Dispatcher.Invoke(del, control, property, value);
}
else
{
PropertyInfo propertyInfo = GetPropertyInfo(property);
if (propertyInfo != null)
{
propertyInfo.SetValue(control, value, null);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我如何称呼它:
tbManufacturer.SetThreadSafeProperty(() => tbManufacturer.Text, "test");
Run Code Online (Sandbox Code Playgroud)
在调试之后,看起来它陷入了无限循环.CheckAcess()为true,它创建了deletegate就好并且可以正确调用.但它继续前进并最终失败.
有关为什么会发生这种情况的任何想法?
这是我正在使用的代码:
SELECT SalesItemPK
,FieldName
,Value /*Convert date to the first of the selected month*/
FROM [Oasis].[dbo].[vw_SALES_SalesItemDetails]
WHERE SalesItemPK IN(
1425
,1225
,1556
,1589
,1599
,1588
,1590)
AND FieldName = 'Estimated Ship Date'
AND CONVERT(DATETIME, Value) >= CONVERT(DATETIME, '1/1/2010')
Run Code Online (Sandbox Code Playgroud)
(我只选择那些PK,因为这些是查询中的所有行.)
这是我收到的错误:
将varchar数据类型转换为日期时间数据类型会导致超出范围的值
以下是从我的视图返回的数据示例.最终的解决方案实际上将值转换为各自月份的第一个.但无论如何都会抛出错误.

当我删除WHERE时,它工作正常.所以有一些奇怪的事情到目前为止我似乎无法弄明白.有任何想法吗?
c# ×6
sql-server ×3
wpf ×3
asp.net ×2
sql ×2
.net ×1
.net-core ×1
alignment ×1
asp.net-core ×1
blend ×1
bulkinsert ×1
csv ×1
ef-core-2.2 ×1
epplus ×1
excel ×1
iis ×1
razor-pages ×1
stretch ×1
t-sql ×1
winforms ×1
xaml ×1