New and Old platforms conversion data import Summary

Source: Internet
Author: User
New and Old platforms conversion data import Summary

A mobile company uses an old internal release platform to update the content of the old platform to the new platform.

ArticleData Import is mainly done by SQL statement insert. Different fields correspond to each other.
However, the problem lies in the attachment data of the old platform, which is saved as binary in the database.
The new publishing platform, the attachment is a normal file.

The number of attachments is not too large. More than one thousand, but manual attachments are enough.
I am a lazy, write a small Program To read binary data from the old database and write it to the directory of the files saved on the new platform.
Insert a data entry into the database of the new platform.
Main Code As follows: // Read and Write files from the database
// I wrote the first code on the Internet, but later I found that the execution efficiency was very low. Failed!
While (Dr. Read ())
{
FS =   New Filestream (filename, filemode. createnew );
BW =   New Binarywriter (FS );
Startindex =   0 ;
Retval = Dr. getbytes ( 2 , Startindex, outbyte, 0 , Buffersize );
While (Retval = Buffersize)
{
Bw. Write (outbyte );
Bw. Flush ();
Startindex + = Buffersize;
Retval = Dr. getbytes ( 2 , Startindex, outbyte, 0 , Buffersize );
}
Bw. Write (outbyte, 0 ,( Int ) Retval -   1 );
Bw. Flush ();
}
// Modified code, OK
While (Dr. Read ())
{
Byte [] TMP;
TMP = ( Byte []) Dr [ " Encls " ];
Bw. Write (TMP );
}

// Writes c: \ test. rmvb to the database, which is a large file used for testing efficiency.
Private   Void Button2_click ( Object Sender, system. eventargs E)
{
Sqlconnection con =   New Sqlconnection ( " Server = (local); uid = sa; Pwd =; database = NETServer " );
Sqldataadapter da =   New Sqldataadapter ( " Select * From DBO. document_appendix " , Con );
Sqlcommandbuilder mycb =   New Sqlcommandbuilder (DA );
Dataset DS =   New Dataset ( " Myimages " );
Da. missingschemaaction = Missingschemaaction. addwithkey;
Filestream FS =   New Filestream ( @" C: \ test. rmvb " , Filemode. openorcreate, fileaccess. Read );
Byte [] Mydata =   New   Byte [Fs. Length];
FS. Read (mydata, 0 , System. Convert. toint32 (FS. Length ));
FS. Close ();
Da. Fill (DS, " Myimages " );
Datarow myrow;
Myrow = DS. Tables [ " Myimages " ]. Newrow ();
Myrow [ " Filename " ] =   " Test. rmvb " ;
Myrow [ " Encls " ] = Mydata;
DS. Tables [ " Myimages " ]. Rows. Add (myrow );
Da. Update (DS, " Myimages " );
Con. Close ();
MessageBox. Show ( " Done! Congratulation! " );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.