服务器上有一张视图,将视图里的部分数据同步到本地数据库表里,当有数十万条数据时,同步特别慢,请问正确的思路是什么:
string sql = "select * from V_BSDT_STUDENT"; //服务器数据库里的视图
DataTable dt = bll.SelectOracleSql(sql); //获取它的所有数据
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow row = dt.Rows[i];
DataTable ds = bll.SelectbySql("select StudentID from WC_Student where StudentID='" + row["XH"].ToString().Trim() + "'"); //本地数据库表里是否存在这条数据
if (ds.Rows.Count > 0)//有则更新
{
string updateSql = "update WC_Student set " +
...
"where StudentID='" + row["XH"].ToString().Trim() + "'";
bll.RunbySql(updateSql);
}
else //没有则增加
{
DataRow newRow;
newRow = bll.SelectbySql("select * from WC_Student where 1=2").NewRow();
...
bll.Insert(newRow, "WC_Student");
}
}
}
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- Request.PathInfo issues and XSS attacks
- How to dynamically load partial view Via jquery aj
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- “Dynamic operations can only be performed in homog
- What is the best way to create a lock from a web a
- Add to htmlAttributes for custom ActionLink helper
SqlBulkCopy 比你这样快多了,楼上正解
可以先用 SqlBulkCopy 插入到临时表中,然后批量更新数据就好了