我们有这个 C# 代码,它将根据结构中的标志更新 SQL Server 数据库表。
public struct stSRK
{
public string Sno;
public string SClaimID;
public bool SType;
public string SText;
}
结构中的数据一次最多可以包含 5000-10000 条记录。目前我们正在使用以下 C# 代码来更新数据库,它会根据结构进行“n”次数据库调用。将有助于有一种替代方法来使用相同的 struct 进行批量更新。请看下面的方法
public int UpdateClaims(List<stSRK> _lt, string strClaimType)
{
try
{
int iCount = 0;
for (int i = 0; i < _lt.Count; i++)
{
if (_lt[i].sType == true)
{
if (_lt[i].SText == 'A')
{
iCount += Convert.ToInt16(SQL.ExecuteSQL("UPDATE table SET ClaimType = '" + strClaimType + "' WHERE
(Sno = '" + _lt[i].Sno + "' AND ClaimID = '" + _lt[i].SClaimID + "')"));
}
else
{
iCount += Convert.ToInt16(SQL.ExecuteSQL("UPDATE table SET ClaimType = '" + strClaimType + "' WHERE
(Sno = '" + _lt[i].Sno + "' AND ClaimID = '" + _lt[i].SClaimID + "')"));
}
}
else
{
if (_lt[i].SText == 'B')
{
iCount += Convert.ToInt16(SQL.ExecuteSQL("UPDATE table SET ClaimType = '" + strClaimType + "' WHERE
(Sno = '" + _lt[i].Sno + "' AND ClaimID = '" + _lt[i].SClaimID + "')"));
}
else
{
iCount += Convert.ToInt16(SQL.ExecuteSQL("UPDATE table SET ClaimType = '" + strClaimType + "' WHERE
(Sno = '" + _lt[i].Sno + "' AND ClaimID = '" + _lt[i].SClaimID + "')"));
}
}
return iCount;
}
catch (Exception e)
{
throw e.Message;
}