0
テキストファイルからフラットファイルデータベースにデータをインポートする必要があります。私はすべてのデータをデータベースにロードするためのより速い方法があると確信していますが、私はその方法を知らないのです。テキストファイルからデータを高速に読み込む方法
private void ImportButton_Click(object sender, EventArgs e)
{
string Path = string.Empty;
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Text File|*.txt";
ofd.ShowDialog();
if (ofd.FileName == string.Empty) return
Path = ofd.FileName;
string data;
using (var sr = new StreamReader(Path))
{
data = sr.ReadToEnd();
}
var items = data.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
var count = 0;
foreach (var info in items.Select(ItemInfo.FromText).Where(info => info != null))
{
count++;
info.Index = ++Envir.ItemIndex;
Envir.ItemInfoList.Add(info);
}
MessageBox.Show(count + " Items have been imported");
UpdateInterface(true);
}
かなり速いようです。 'var items = File.ReadAllLines(Path);'と書くことで、コードを小さくすることができます。 – Enigmativity
'Envir.ItemInfoList.Add(info);' - これはデータベースに書き込む場所ですか? –
Envir.ItemInfoListの実装方法については言及していません。 Entity Frameworkのようなものへの同期呼び出しであれば、そのステップを改善することができます。 DBは一括挿入をサポートしていますか?それを調べる。 –