Using System;
Using System. collections;
Using System. configuration;
Using System. Data;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. htmlcontrols;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using Food. BLL;
Using Food. models;
Using Food. Dal;
Public Partial ClassTest_importxls: system. Web. UI. Page
{
Protected VoidPage_load (ObjectSender, eventargs E)
{
Importdata ();
}
Private Dataset external data ( String Filepath)
{
String Strcon = " Provider = Microsoft. Jet. oledb.4.0; Data Source = " + Filepath + " ; Extended properties = 'excel 8.0; IMEX = 1' " ;
System. Data. oledb. oledbconnection Conn = New System. Data. oledb. oledbconnection (strcon );
String Strcom = " Select * from [sheet1 $] " ;
Conn. open ();
System. Data. oledb. oledbdataadapter mycommand = New System. Data. oledb. oledbdataadapter (strcom, Conn );
Dataset DS = New Dataset ();
Mycommand. Fill (DS, " [Sheet1 $] " );
Conn. Close ();
Return DS;
}
Private Void Importdata ()
{
// Batch add
Try
{
String Fileurl = @" C: \ Documents and Settings \ Administrator \ Desktop \ insidelink.xls " ;
Dataset DS = New Dataset (); // Retrieve a dataset
DS = Encrypted data (fileurl );
For ( Int I = 0 ; I < DS. Tables [ 0 ]. Rows. Count; I ++ )
{
String Typename = DS. Tables [ 0 ]. Rows [I] [ " Class Name " ]. Tostring ();
If (Typename. Length > 0 )
{
String Linkvalue = DS. Tables [ 0 ]. Rows [I] [ " Link " ]. Tostring ();
Dbhelper. executecommand ( " Insert into replacekeyword values (' " + Typename + " ',' " + Linkvalue + " ', '', 1, 1) " );
// Dbhelper contains the connection string
}
Else
{
Break ;
}
}
Response. Write ("OK");
}
Catch(Exception ERR)
{
Response. Write ("Error");
}
}
}