目前有几十万数据,现在要求对其中的数据进行程序更新,目前具体思路是这
1、要更新的数据进行处理存入数组
2、用sql语句进行批量
代码如下
string[] id = new string[1000000];
string[] Detail = new string[1000000];
string[] Catalog = new string[1000000];
string[] Foreword = new string[1000000];
string[] AuthorIntroducer = new string[1000000];
int count = 0;
string strsql = "select id,Detail,Catalog,Foreword,AuthorIntroducer from PT order by id ";
SqlDataReader dr = new DataAccess().dataReader(strsql);
while(dr.Read())
{
id[count] = dr["id"].ToString();
Detail[count] = StringUnity.ReplaceLineCode(new Verify().DoNullString(dr["Detail"]));
Catalog[count] = StringUnity.ReplaceLineCode(new Verify().DoNullString(dr["Catalog"]));
Foreword[count] = StringUnity.ReplaceLineCode(new Verify().DoNullString(dr["Foreword"]));
AuthorIntroducer[count] = StringUnity.ReplaceLineCode(new Verify().DoNullString(dr["AuthorIntroducer"]));
count = count + 1;
}
dr.Close(); for (int i = 0; i < count; i++)
{
strsql = " update PT set Detail='" + StringUnity.FormatString(Detail[count])
+ "',Catalog='" + StringUnity.FormatString(Catalog[count])
+ "',Foreword='" + StringUnity.FormatString(Foreword[count])
+ "',AuthorIntroducer='" + StringUnity.FormatString(AuthorIntroducer[count])
+ "' where id=" + id[count];
new DataAccess().ExecuteNonQuerySql(strsql);
}
1、要更新的数据进行处理存入数组
2、用sql语句进行批量
代码如下
string[] id = new string[1000000];
string[] Detail = new string[1000000];
string[] Catalog = new string[1000000];
string[] Foreword = new string[1000000];
string[] AuthorIntroducer = new string[1000000];
int count = 0;
string strsql = "select id,Detail,Catalog,Foreword,AuthorIntroducer from PT order by id ";
SqlDataReader dr = new DataAccess().dataReader(strsql);
while(dr.Read())
{
id[count] = dr["id"].ToString();
Detail[count] = StringUnity.ReplaceLineCode(new Verify().DoNullString(dr["Detail"]));
Catalog[count] = StringUnity.ReplaceLineCode(new Verify().DoNullString(dr["Catalog"]));
Foreword[count] = StringUnity.ReplaceLineCode(new Verify().DoNullString(dr["Foreword"]));
AuthorIntroducer[count] = StringUnity.ReplaceLineCode(new Verify().DoNullString(dr["AuthorIntroducer"]));
count = count + 1;
}
dr.Close(); for (int i = 0; i < count; i++)
{
strsql = " update PT set Detail='" + StringUnity.FormatString(Detail[count])
+ "',Catalog='" + StringUnity.FormatString(Catalog[count])
+ "',Foreword='" + StringUnity.FormatString(Foreword[count])
+ "',AuthorIntroducer='" + StringUnity.FormatString(AuthorIntroducer[count])
+ "' where id=" + id[count];
new DataAccess().ExecuteNonQuerySql(strsql);
}
直接填充到DataTable,然后更新DataTable的数据,再用SqlDataAdapter.Update多方便,搞什么数组?
1.你说的好像可以直接用SQL语句处理
如:UPDATE TABLE1 SET a='***' INNER JOIN TABLE2 ON TABLE1.id=TABLE2.ID WHERE ...
2.如楼上所迷,直接用SqlDataAdapter更新