Import a file to a database table through datatable

Source: Internet
Author: User

Private void importtemplate ()
{
Savefiledialog SFD = new savefiledialog ();
Try
{
Emrtemplateclient etc = factory. getemrtemplate ();
Service. weizoserver. tem_file_text model = new tem_file_text ();
Folderbrowserdialog FBD = new folderbrowserdialog ();
If (FBD. showdialog () = dialogresult. OK)
{
String filepath = FBD. selectedpath;
Directoryinfo DIC = new directoryinfo (filepath );
Int items = 0; // Number of inserted rows
Foreach (fileinfo fi in DIC. getfiles ())
{
If (Fi. Extension = ". EMR ")
{
String filename = Fi. Name;
Int Index = filename. indexof ('.');
If (index> 0)
{
Filestream FS = new filestream (filepath + "\" + filename, filemode. Open );
Byte [] buffer = new byte [fs. Length];
FS. Read (buffer, 0, buffer. Length );
FS. Seek (0, seekorigin. Begin );
Model. file_text = buffer;
FS. Close ();
Filename = filename. Remove (INDEX );
Model. tem_code = filename;
Items = etc. add_tem_file_text (model );
Items ++;
}
}
If (Fi. Extension = "")
{
Tem_file_index Index = new tem_file_index ();
String filename = Fi. Name;
Using (streamreader sr = new streamreader (filepath + "\" + filename, encoding. Default ))
{
String line;
While (line = Sr. Readline ())! = NULL)
{
String [] Cell = line. Split ('| ');
Index. tem_code = cell [0];
Index. ds_id = cell [1];
Index. tem_class = cell [2];
Index. p_code = cell [3];
Index. tem_name = cell [4];
Index. range_id = cell [5];
Index. range_name = cell [6];
If (cell [7]! = "")
{
Index. range_falg = convert. toint32 (cell [7]);
}
Index. audit_userid = cell [8];
Index. audit_username = cell [9];
If (cell [10]! = "")
{
Index. audit_time = convert. todatetime (cell [10]);
}
Index. creat_userid = cell [11];
Index. creat_username = cell [12];
If (cell [13]! = "")
{
Index. creat_time = convert. todatetime (cell [13]);
}
Index. last_userid = cell [14];
Index. last_username = cell [15];
If (cell [16]! = "")
{
Index. last_time = convert. todatetime (cell [16]);
}
Index. remark = cell [17];
If (cell [18]! = "")
{
Index. data_model_class = convert. toint32 (cell [18]);
}
Index. data_model_code = cell [19];
If (cell [20]! = "")
{
Index. file_falg = convert. toint32 (cell [20]);
}
If (cell [21]! = "")
{
Index. del_flag = convert. toint32 (cell [21]);
}
Index. monitor_code = cell [22];
If (cell [23]! = "")
{
Index. level_flag = convert. toint32 (cell [23]);
}
If (cell [24]! = "")
{
Index. auto_page = convert. toint32 (cell [24]);
}
Index. tem_attr = cell [25];
If (cell [26]! = "")
{
Index. system_flag = convert. toint32 (cell [26]);
}
Etc. add_tem_file_index (INDEX );
}

}

}
}
MessageBox. Show (items + "row data affected ");
}
}

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.