为什么我导入数据库的时候
为什么到如的时候差一条 每次都少导入一条不知道为什么
if (FileUpload1.HasFile)
{
string conpath = this.FileUpload1.PostedFile.FileName;
string type = System.IO.Path.GetExtension(conpath);
string filePath = Server.MapPath( "~/admin/upfiles/ ") + DateTime.Now.ToString( "yyyyMMddHHmmss ")+System.IO.Path.GetFileName(conpath) ;
// 假设 upload 为你上传的服务器目标的文件夹
FileUpload1.PostedFile.SaveAs(filePath);
string constr = "provider=microsoft.jet.oledb.4.0;data source= ' " + filePath + " ';Extended Properties=Excel 8.0;HDR=Yes;IMEX=1; ";
OleDbConnection conn = new OleDbConnection(constr);
#region try
try
{
conn.Open();
DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
// DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string tname = dt.Rows[0][ "TABLE_NAME "].ToString();
string query = "SELECT * FROM [ " + tname + "] ";
OleDbCommand com = new OleDbCommand(query, conn);