我知道这些问题相当普遍,但我整天都在搜索,但我找不到合适的方法.
这是我的代码,使用C#将大约100 000个虚拟记录插入到MDB文件中.
OleDbConnection con = new OleDbConnection();
string dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;";
string dbSource = "Data Source = D:/programming/sample.mdb";
con.ConnectionString = dbProvider + dbSource;
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "INSERT INTO tblBooks (Title, Price, Tag, Author) VALUES (@title, @price, @tag, @author)";
cmd.Parameters.AddWithValue("@title", "Dummy Text 1");
cmd.Parameters.AddWithValue("@price", 10);
cmd.Parameters.AddWithValue("@tag", "Dummy Text 2");
cmd.Parameters.AddWithValue("@author", "Dummy Text 3");
con.Open();
for (int i = 0; i < 100000; i++)
{
cmd.ExecuteNonQuery();
}
con.Close();
Run Code Online (Sandbox Code Playgroud)
此代码大约需要一分钟才能运行.这是正常的吗?更快地做到这一点的正确方法是什么?
我为这个含糊不清的标题道歉.我不能同时保持清晰和简洁.所以随时改变它.
我有一个很大的列表,其中包含其他几个列表.这些内部列表包含Column对象.
List<List<Column>> listOfAllColumns;
Run Code Online (Sandbox Code Playgroud)
假设我的内部列表包含不同的Column对象,如下所示:
list1 = {c1, c1, c2}
list2 = {c1, c2, c1}
list3 = {c2, c3}
list4 = {c1,c1, c2}
Run Code Online (Sandbox Code Playgroud)
大列表包含以下列表:listOfAllColumns = {list1,list2,list3,list4}
现在我想要一个从listOfAllColumns列表中删除重复列表的方法.例如,它将查看上面的列表并删除list4.
list1: c1,c1,c2
list2: c1,c2,c1
list3: c2,c3
list4: c1,c1,c2 (it is equal to list1 so it is a duplicate)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
public class ColumnList
{
public void RemoveDuplicateColumnTypes()
{
Column c1 = new Column() { SectionName = "C50", StirrupType = "Tie" };
Column c2 = new Column() { SectionName = "C50", StirrupType = …Run Code Online (Sandbox Code Playgroud) ModelBeams是一个List<ModelBeam>,linesPassingThroughBeamEndsInYDirection是一个List<double>.
如何foreach使用LINQ?编写以下循环?
foreach (var beam in ModelBeams)
{
linesPassingThroughBeamEndsInYDirection.Add(beam.ConnectivityLine.I.Y);
linesPassingThroughBeamEndsInYDirection.Add(beam.ConnectivityLine.J.Y);
}
Run Code Online (Sandbox Code Playgroud) 如何在VBA/ADO中获取RecordSet的其他行?
我正在使用下面的代码,但这只给了我第一行。例如,记录集第三行的第二项怎么样?
Debug.Print recordSet.Fields(0)
Run Code Online (Sandbox Code Playgroud) 我怎样才能double按特定方式舍入a precision.我需要一个函数来获取a double并返回最接近该double的值,该值是该特定的倍数precision并且低于double.
因此,例如,如果精度= 2.5
9.3 ---> 7.5
12.5 ---> 12.5
13.0 ---> 12.5
14.5 ---> 12.5
15.5 ---> 15.0
Run Code Online (Sandbox Code Playgroud) 在这里,我试图将组合框绑定到列表代码.组合框显示:A和B.
<ComboBox ItemsSource="{Binding Path=Codes}"/>
public SettingsWindow()
{
InitializeComponent();
Codes = new List<Code> {Code.A, Code.B};
DataContext = this;
}
Run Code Online (Sandbox Code Playgroud)
我已经定义了一个转换器来在组合框中显示更易理解的信息:
public class CodeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var code = (Code)value;
string text;
if (code == Code.A)
{
text = "ACI318-99";
}
else
{
text = "ACI318-11";
}
return text;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何在我的XAML中使用这个转换器,所以我的组合框中会有ACI318-99和ACI318-11.
假设我们有一个Line由Point startPoint和定义的类Point endPoint。
如果我有这些行的列表,如何List<Point>使用LINQ将它们中的所有点提取为一个。
这是我到目前为止的内容:
IList<Point> points1 = lines.Select(o => o.StartPoint).ToList();
IList<Point> points2 = lines.Select(o => o.EndPoint).ToList();
IList<Point> points = points1.Concat(points2).ToList();
Run Code Online (Sandbox Code Playgroud) 我有这个简单的XAML,我如何可以改变Text的财产TextBlock在UserControl1从MainWindow?
<Window x:Class="RefactorXAML.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:refactorXaml="clr-namespace:RefactorXAML"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"></RowDefinition>
<RowDefinition Height="100"></RowDefinition>
</Grid.RowDefinitions>
<Grid>
<refactorXaml:UserControl1></refactorXaml:UserControl1>
</Grid>
<Grid Grid.Row="1">
<Button>Change Text</Button>
</Grid>
</Grid>
</Window>
<UserControl x:Class="RefactorXAML.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<TextBlock x:Name="MyTextblock">StackOverflow</TextBlock>
</UserControl>
Run Code Online (Sandbox Code Playgroud) 我如何使用GroupBy获得一个明确的点列表.我想消除重复点.
List<_3DPoint> list_of_points = new List<_3DPoint> { ... };
public class _3DPoint
{
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
}
Run Code Online (Sandbox Code Playgroud) 在一个MultiBinding如果DataContext设置为VM1和C是的一个属性,是有可能做第二结合不同的DataContext像VM2并将其绑定到D属性中VM2?
<MultiBinding Converter="{StaticResource UnitConverter}">
<Binding Path="C"/>
<Binding Path="D"/>
</MultiBinding>
Run Code Online (Sandbox Code Playgroud) c# ×8
list ×3
wpf ×3
linq ×2
ms-access ×2
xaml ×2
ado ×1
combobox ×1
data-binding ×1
datacontext ×1
group-by ×1
multibinding ×1
oledb ×1
vba ×1