如何从数据集中插入大约 300 条记录到数据库中?大约需要 5 分钟,我想知道有什么方法可以使用数据集改进这个过程吗?
编辑:这是我的代码,当用户单击 sav 时,它将执行以下过程:
public void ProcessSkalaGaji(MyDataSet myDataSet, DateTime tanggalBerlaku, decimal percentage)
{
GenerateNewSkalaGaji(myDataSet, tanggalBerlaku, percentage);
InsertSkalaGaji(myDataSet);
}
private void GenerateNewSkalaGaji(MyDataSet myDataSet, DateTime tanggalBerlaku, decimal percentage)
{
// GetLastSkalaGaji returns about 300 rows
MyDataSet.SkalaGajiDataTable skalaGajiTable = GetLastSkalaGaji();
foreach (MyDataSet.SkalaGajiRow skalaGajiRow in skalaGajiTable.Rows)
{
MyDataSet.SkalaGajiRow newSkalaGajiRow = myDataSet.SkalaGaji.NewSkalaGajiRow();
newSkalaGajiRow.TanggalBerlaku = tanggalBerlaku;
newSkalaGajiRow.Golongan = skalaGajiRow.Golongan;
newSkalaGajiRow.MasaKerja = skalaGajiRow.MasaKerja;
newSkalaGajiRow.GajiPokok = skalaGajiRow.GajiPokok + (skalaGajiRow.GajiPokok * percentage / 100);
myDataSet.SkalaGaji.AddSkalaGajiRow(newSkalaGajiRow);
}
}
private string InsertSkalaGaji(MyDataSet myDataSet)
{
string errorMsg = string.Empty;
if (myDataSet.HasChanges() && !myDataSet.HasErrors)
{
int rowsAffected = Adapter.Update(myDataSet.SkalaGaji);
if (rowsAffected == 0)
{
errorMsg = "No rows inserted! Please contact your administrator";
}
}
return errorMsg;
}
谢谢