Home > Net >  For c # start release "path in the form of illegal", "System. ArgumentException"
For c # start release "path in the form of illegal", "System. ArgumentException"

Time:11-21

The static void SyncDataOne (url string, the string table, int page
{
Console.WriteLine();

//download file
Byte [] b=new System.Net.WebClient () DownloadData (url);
//return json interface
. String json=System. Text. Encoding UTF8. Get string (b);
//calculate the hash
String md5=utilty. Md5 (json);
//get data set
System. Data. DataTable DataTable=utilty. JsonToDataTable (url, json, new string [] {" Data ", "result"});
//string md5=dataTable. Rows. Count. The ToString ();

The Console. Write (" file {0} has been downloaded, contains data line {1}, ", url, dataTable. Rows. Count);
If (dataTable. Rows. Count==0)
{
The Console. Write (" mission accomplished!" );
return;
}
if (dataTable. Rows. Count & lt; 1000)
{
The Console. Write (" is checking data volume... ");
Using (var conn=new SqlConnection ())
{
Conn. The ConnectionString=ConfigurationManager. AppSettings [" conn "];
conn.Open();
//check database md5
Using (SqlCommand command=conn. CreateCommand ())
{
Command.Com mandText="select md5 from tb_download where url=@ url and status=1";
//by the
//the Console. Write mandText (command.Com);

Command. The Parameters. AddWithValue (" url ", url);

The object obj=command. ExecuteScalar ();


//if the same exists and md5 skip processing,
If (obj!=null & amp; & Obj. ToString ()==md5)
{
The Console. Write (" no update data, ");
return;
}

/update/insert
Command.Com mandText=@ "delete from tb_download where url=@ url;
Insert into tb_download (id, url, data, md5, rowtime, status)
Values (newid (), @ url, @ data, @ md5, getdate (), 0) ";
Command. The Parameters. AddWithValue (" md5 ", md5);
Command. The Parameters. AddWithValue (" data ", json);
The command. ExecuteNonQuery ();

//delete the update data
Command.Com mandText=the string. Format (" delete from {0} where url=@ url ", table).
The command. ExecuteNonQuery ();

//have change according to the url to update the target table

Using (System. The Data. SqlClient. SqlBulkCopy BCP=new SqlBulkCopy (conn))
{

Foreach (System. Data. The DataColumn c in dataTable. Columns)
{

BCP. ColumnMappings. Add (Arthur c. olumnName, Arthur c. olumnName);
}



BCP. DestinationTableName=table;

Try
{
BCP. WriteToServer (dataTable);
}
The catch (Exception ex)
{
Console. WriteLine (ex. Message);
}

}

//update the task status
Command.Com mandText="update tb_download set status=1 where url=@ url";
The command. ExecuteNonQuery ();
}
//by 20200529
If (dataTable. Rows. Count==1000)
{
Console. WriteLine (" the second page ");
Page=2;
If (page==2)
{
Url=url + "& amp; Page="+ page;
SyncDataOne (url, table, 2);
}
}
If (page==2)
{
The Console. Write (" the second page tasks over!" );
return;
}
//by end


//update the task status
//command.Com mandText="exec sync_done";
//command. ExecuteNonQuery ();
}


The Console. Write (" record has been updated, ");

}



Changed the red code is error.. The article not when a number is equal to 1000..
  •  Tags:  
  • C#
  • Related