Read and import SQL Server from Excel

Source: Internet
Author: User
  /**/ /// <Summary>
///Import SQL Server after reading from Excel
/// </Summary>
Public   Void Readexcel ()
{
String SQL =   " Provider = Microsoft. Jet. oledb.4.0; Data Source = "   + Server. mappath ( " Teachers.xls " ) +   " ; Extended properties = Excel 8.0 " ;
Oledbconnection CNN =   New Oledbconnection (SQL );
CNN. open ();
Oledbdataadapter ODA =   New Oledbdataadapter ( " Select * from [Instructor $] " , CNN );
Dataset DS =   New Dataset ();
ODA. Fill (DS );
CNN. Close ();

Int Count = DS. Tables [ 0 ]. Rows. count;
For ( Int I =   0 ; I < Count; I ++ )
{
Jzgjbxx Model =   New Jzgjbxx ();
Model. jzgid = DS. Tables [ 0 ]. Rows [I] [ " Jzgid " ]. Tostring ();
Model. jzgbm = DS. Tables [ 0 ]. Rows [I] [ " Jzgbm " ]. Tostring ();
Model. xxid = DS. Tables [ 0 ]. Rows [I] [ " Xxid " ]. Tostring ();
Model. XM = DS. Tables [ 0 ]. Rows [I] [ " XM " ]. Tostring ();
Model. yhid = DS. Tables [ 0 ]. Rows [I] [ " Yhid " ]. Tostring ();
Model. sfzh = DS. Tables [ 0 ]. Rows [I] [ " Sfzh " ]. Tostring ();
If (Ds. Tables [ 0 ]. Rows [I] [ " Csrq " ]. Tostring () ! =   "" )
{
Model. csrq=Datetime. parse (Ds. Tables [0]. Rows [I] ["Csrq"]. Tostring ());
}
Else
{
Model. csrq=Datetime. now;
}
Model. xbbm = DS. Tables [ 0 ]. Rows [I] [ " Xbbm " ]. Tostring ();
Model. mzbm = DS. Tables [ 0 ]. Rows [I] [ " Mzbm " ]. Tostring ();
Model. whcdbm = DS. Tables [ 0 ]. Rows [I] [ " Whcdbm " ]. Tostring ();
Model. zcbm = DS. Tables [ 0 ]. Rows [I] [ " Zcbm " ]. Tostring ();
Model. jszgbm = DS. Tables [ 0 ]. Rows [I] [ " Jszgbm " ]. Tostring ();
Model. dyxlbm = DS. Tables [ 0 ]. Rows [I] [ " Dyxlbm " ]. Tostring ();

Model. zzmmbm = DS. Tables [ 0 ]. Rows [I] [ " Zzmmbm " ]. Tostring ();
Model. bzlbbm = DS. Tables [ 0 ]. Rows [I] [ " Bzlbbm " ]. Tostring ();
Model. rkzkbm = DS. Tables [ 0 ]. Rows [I] [ " Rkzkbm " ]. Tostring ();
Model. gwzybm = DS. Tables [ 0 ]. Rows [I] [ " Gwzybm " ]. Tostring ();
Model. dzxx = DS. Tables [ 0 ]. Rows [I] [ " Dzxx " ]. Tostring ();
Model. bz = DS. Tables [ 0 ]. Rows [I] [ " BZ " ]. Tostring ();
Model. scbz = DS. Tables [ 0 ]. Rows [I] [ " Scbz " ]. Tostring ();
If (Ds. Tables [ 0 ]. Rows [I] [ " Cjny " ]. Tostring () ! =   "" )
{
Model. cjrq=Datetime. parse (Ds. Tables [0]. Rows [I] ["Cjny"]. Tostring ());
}
Else
{
Model. cjrq=Datetime. now;
}
If (Ds. Tables [ 0 ]. Rows [I] [ " Cjgzny " ]. Tostring () ! =   "" )
{
Model. cjgzrq=Datetime. parse (Ds. Tables [0]. Rows [I] ["Cjgzny"]. Tostring ());
}
Else
{
Model. cjgzrq=Datetime. now;
}
If (Ds. Tables [ 0 ]. Rows [I] [ " Lxny " ]. Tostring () ! =   "" )
{
Model. lbxgzrq=Datetime. parse (Ds. Tables [0]. Rows [I] ["Lxny"]. Tostring ());
}
Else
{
Model. lbxgzrq=Datetime. now;
}
( New Jzgjbxxbll (). Create (model );
}
DS. Clear ();
}
Related Article

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.