the format must be unified. Otherwise, the Program cannot be determined based on any criteria,
# region returns a table in the opened workbook and forms a datatable
///
/// returns a table in the opened workbook and form a datatable
///
/// absolute file path
// name of the table to be opened
// returns the datatable database set
Private void readexcel ()
{
Try
{
Datatable rs = new datatable ();
Rs = NULL;
Dataset RDS = NULL;
String strconn = "";
Int COUNT = 0;
String id = request ["ID"];
Datetime createtime = datetime. now;
String date = createtime. year. tostring () + "-" + createtime. month. tostring () + "-" + createtime. day. tostring () + "" + createtime. hour. tostring () + ":" + createtime. minute. tostring () + ":" + createtime. second. tostring ();
String sqlstr = "select * From tab_uppart_file where id =" + ID + "";
String userid = data1.readout (sqlstr, 1 );
String filename = data1.readout (sqlstr, 3 );
String Path = server. mappath ("../upparts/" + filename );
String filepath = ".. \ upparts \" + filename;
If (file. exists (server. mappath (filepath) // checks whether the file exists.
{
Strconn = "provider = Microsoft. jet. oledb.4.0; Data Source = "+ path +"; extended properties = 'excel 8.0; HDR = yes; IMEX = 1'; "; // IMEX = 1 to convert text
Oledbconnection conn = new oledbconnection (strconn );
Oledbdataadapter mycommand = new oledbdataadapter ("select * from [sheet1 $]", strconn );
Dataset mydataset = new dataset ();
Mycommand. Fill (mydataset, "[sheet1 $]");
Foreach (datarow row in mydataset. Tables [0]. Rows)
{
Count ++;
String classid = "";
String name = "";
String Model = "";
String price = "";
String num = "";
String MFG = "";
String package = "";
String remark = "";
Classid = row ["product type"]. tostring ();
Name = row ["Product Name"]. tostring ();
Model = row ["Product Model"]. tostring ();
Price = row ["product price"]. tostring ();
Num = row ["quantity"]. tostring ();
MFG = row ["manufacturer"]. tostring ();
Package = row [""]. tostring ();
Remark = row ["transaction description"]. tostring ();
If (name! = "" & Model! = "")
{
Sqlstr = "insert into tab_part values ('" + name + "', '" + model + "', '" + num + "', '" + package + "', '"+ MFG +"', '"+ Price +"', '"+ remark +"', '"+ classid +"', '"+ createtime + "', '"+ userid +"', '0 ')";
Data1.moddata (sqlstr );
}
}
String updatesql = "Update tab_uppart_file set flag = '1', uploadtime = '" + date + "'where id ='" + ID + "'";
Data1.moddata (updatesql );
Data1.alert2 ("Upload record successful! "," Batchaddparts. aspx ", page );
}
Else
{
Data1.alert2 ("corresponding template file not found", "batchaddparts. aspx", page );
}
}
Catch (system. Data. oledb. oledbexception ex)
{
Response. Write (ex. Message );
}
}
# Endregion