Read and import SQL Server from Excel
Last Update:2018-12-06
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 ();
}