【发布时间】:2012-02-09 16:11:51
【问题描述】:
如何使用数据表进行多次更新?
我发现了这个Update 1 row
我的代码:
public void ExportCSV(string SQLSyntax, string LeFile, bool Is_Ordre, int TypeDonne)
{
try
{
using (var connectionWrapper = new Connexion())
{
var connectedConnection = connectionWrapper.GetConnected();
SqlDataAdapter da = new SqlDataAdapter(SQLSyntax, connectionWrapper.conn);
DataSet ds = new DataSet();
da.Fill(ds, "Emp");
DataTable dt = ds.Tables["Emp"];
CreateCSVFile(dt, LeFile, Is_Ordre, TypeDonne);
//Update all lines, it not save in Database
foreach (DataRow row in dt.Rows)
{
row["IS_IMPORT"] = true;
}
}
}
catch (Exception excThrown)
{
throw new Exception(excThrown.Message);
}
}
问题是:
foreach (DataRow row in dt.Rows)
{
row["IS_IMPORT"] = true;
}
它不会将其保存到数据库中。
提前谢谢你, 史蒂夫
【问题讨论】:
-
当心:这种方法会消耗大量内存。如果您的表的行数超过 1000 行(任意数),则会对内存产生很大影响。你为什么不移动到 SqlDataReader,它可以逐行读取,然后使用文件流将字符串行附加到 csv 文件