我需要在我的数据库中插入一大堆东西
写出来的是查询将是这样的事情(但有更多的东西!)
Insert into MyTable (country_id, event) values (1001, 'up')
Insert into MyTable (country_id, event) values (1001, 'down')
Insert into MyTable (country_id, event) values (1002, 'up')
Insert into MyTable (country_id, event) values (1003, 'down')
....
Insert into MyTable (country_id, event) values (9999, 'up')
Insert into MyTable (country_id, event) values (9999, 'down')
Run Code Online (Sandbox Code Playgroud)
我可以编写一些神奇的SQL连接/合并奇迹查询,它将获得所有country_ids和所有"事件"类型并创建我需要的数百个插入语句吗?
编辑:
有一张国家/地区表.哪个应插入到MyTable中是sql查询的结果,该查询的每个结果都需要MyTable中的"向上"和"向下"行.有足够的,我不想手动策划查询.
实际上,除了"向上"和"向下"之外,它们可以手动输入,或者作为进一步查询的结果.
我有一个课程heirarсhy:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyProject.Models;
using MyProject.Extensions;
namespace MyProject.Models
{
public abstract class Vehicle
{
public string Color { get; set; }
}
public class Car : Vehicle
{
public int Mileage { get; set; }
}
public class Boat : Vehicle
{
public int Displacement { get; set; }
}
}
namespace MyProject.Extensions
{
public static class VehicleExtensions
{
public static IEnumerable<Vehicle> FilterByColor(this IEnumerable<Vehicle> source, string color)
{
return source.Where(q => …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用odbcConnection通过VS C#2010 Express版本的“属性”菜单中的ConnectionString连接到Access DB。我收到一条错误消息,告诉我该选项在Express版本中未启用,我被迫使用其他版本或代码。
如何使用代码进行此连接?
在我的代码中,我有许多带有此签名的函数(params + return类型),它们都使用同一个try-catch子句.
public ActionResult methodName(int id)
{
try
{
//Some specific code here
return new HttpStatusCodeResult(HttpStatusCode.OK);
}
catch (Exception ex)
{
return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,这是一遍又一遍地复制,我知道复制很糟糕.发生这种情况的原因是因为我希望代码能够返回多个HttpStatusCodeResult但我不知道更好的方法.
在此示例中,我返回内部服务器错误和正常答案.但是,如果我想返回另一种类型的错误怎么办?
public ActionResult methodName(int id)
{
try
{
//Some specific code here
if(conditionA)
return return new HttpStatusCodeResult(HttpStatusCode.NotFound, "No Hamsters found!")
return new HttpStatusCodeResult(HttpStatusCode.OK);
}
catch (Exception ex)
{
return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的代码中是否有一种模块化的行为方式,没有复制?我可以使用设计或建筑模式吗?如果是这样,哪一个?
c# design-patterns exception-handling architectural-patterns
我目前正在处理用户控件并坚持依赖对象类的自定义属性IsEnabled被识别但不是FooText
XAML:
<ScrollViewer VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Hidden"
sc:TouchScrolling.IsEnabled = "true"
Grid.Row="0" Grid.Column="1">
Run Code Online (Sandbox Code Playgroud)
我需要在sc:TouchScrolling元素上设置更多属性,但VS一直抱怨它无法找到属性.
TouchScrolling元素继承自Dependency Object
public class TouchScrolling : DependencyObject
{
public bool IsEnabled
{
get { return (bool)GetValue(IsEnabledProperty); }
set { SetValue(IsEnabledProperty, value); }
}
public static readonly DependencyProperty IsEnabledProperty =
DependencyProperty.RegisterAttached("IsEnabled", typeof(bool), typeof(TouchScrolling), new UIPropertyMetadata(false, IsEnabledChanged));
//FooText is not recognized
public string FooText
{
get { return (string)GetValue(FooTextProperty); }
set { SetValue(FooTextProperty, value); }
}
Run Code Online (Sandbox Code Playgroud) 在我C#度过了大半生的生活之后,我最近开始做一些编程PHP.
在PHP我能做到这一点:
class User
{
public __construct($UserId)
{
// Do stuff
}
}
class Employee extends User
{
public __construct($EmployeeId)
{
// Look up the UserId connected to $EmployeeId
$UserId = hypothetical_get_user_id_func($EmployeeId);
parent::__construct($UserId);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,C#我似乎没有这种可能性,因为$UserId在它进入第一个构造函数之前,我似乎必须知道它.
public class User
{
public User(int UserId)
{
// Do stuff
}
}
public class Employee : User
{
public Employee(int EmployeeId) : base(***) // I don't know this value yet?
{
// This …Run Code Online (Sandbox Code Playgroud) 我有1个长字符串,看起来像:"item1, item7, item9"etc。然后我有一个列表,看起来像:
"item2",
"item3",
"item9"
Run Code Online (Sandbox Code Playgroud)
我想检查一下列表字符串是否与长字符串中的任何内容匹配。我可以使用一个foreach循环,但是我在想必须有一个简单的LINQ表达式,但我似乎不太正确。
我只是在使用Microsoft Virtual Academy学习C#.这是我正在使用的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Variables
{
class Program
{
static void Main(string[] args)
{
Car myCar = new Car("BWM", "745li", "Blue", 2006);
printVehicleDetails(myCar);
Console.ReadLine();
}
}
abstract class Vehicle
{
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public string Color { get; set; }
public abstract string FormatMe();
public static void printVehicleDetails(Vehicle vehicle)
{
Console.Writeline("Here are …Run Code Online (Sandbox Code Playgroud) c# ×7
class ×1
constructor ×1
inheritance ×1
linq ×1
ms-access ×1
oop ×1
sql ×1
sql-server ×1
wpf ×1