120 days of 1200 hours of pass-through for junior students. NET (iii)

Source: Internet
Author: User

1, use the using (Declaration object), using to invalidate the local object, when it is used, either its containing class implements the IDispose interface, or his parent class implements the IDispose interface.

2, Fuzzy query:% for 0 to more than any character; _ represents an arbitrary character; [] place a range in the middle; ^ put in [] represents non (not in this range)

3,npoi Implementing Excel Export Import:

Export to Excel::: (1) The tables in the database are read out and stored in their objects with SqlDataReader

(2) Create an object wk for the Iworkbook interface and give it a file stream parameter--filestream FSREAD=FILE.O
Penread (); Workbooks

(3) wk. Numberofsheet represents the number of worksheets; wk. Getsheetat (index) Gets the table, the object that created the Isheet interface sheet isheet sheet = wk.   Createsheet ("Tb_user"); Work table

(4) sheet. Lastrownum represents the index value of the last row; Create IRow object

(5) However row. Lastcellnum represents the last column of the column index value +1; Create Icell Object

Note: Fields with null values in the database should be judged when writing to Excel

Method One: if (! =null)

{

Row. Createcell (3). Setcellvalue (HEADMAP);//If it is not empty, the cell is used. (another meaning is that if it is empty, then this cell is skipped and not assigned, which is not used)

}

Method Two: if (HEADMAP)

{

The Cell object. Empty cells

Cellheadmap.setcelltype (Celltype.blank);

}

                                   else
                               {
                                         Cellheadmap.setcellvalue (Headmap );
                              }

(6) Last executed FileStream fswrite=file.openwrite ("filename")

Wk. Write (File stream object Fswrite)

Excel Import to table:::

(1) Read Excel

(2) IRow row = sheet. GetRow (i);

(3) String name = row. Getcell (1). stringcellvalue;/////Example Value/////

(4) Determine if the cell is not empty or the cell format is not blank, the normal assignment, otherwise the assignment is null

(5) When there is a value of NULL, it is not possible to insert null into the database, to insert DBNull.Value. New SqlParameter ("@HeadMap", Headmap==null? DBNull.Value: (object) headmap);//////

Note://when inserting a date
When the Excel date goes to the database, use datetime.fromoadate;
Excel controls insert a database with DBNull.Value
Onject (Datetime.fromoadate ((double) lockdate))

120 days of 1200 hours of pass-through for junior students. NET (iii)

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.