Excel未检查C#代码asp.net中的第二行

Excel未检查C#代码asp.net中的第二行,c#,asp.net,excel,C#,Asp.net,Excel,我正在上传一个excel文件,以验证是否上传了正确的数据。为此,我正在检查下面代码中的条件 我采取的方案是:- 我坐三排。其中excel中的第一行正确,excel的第二行有一些无效数据,第三行为空 所以我想要的是,如果其中任何一行有无效数据,那么excel就不应该被上传 我尝试了下面的代码,但它只检查第一行,不检查其他两行,然后上传。请帮忙 public void UploadHotoExcel() { HttpPostedFile=fluHotoUpload.PostedFile; byte

我正在上传一个excel文件,以验证是否上传了正确的数据。为此,我正在检查下面代码中的条件

我采取的方案是:-

我坐三排。其中excel中的第一行正确,excel的第二行有一些无效数据,第三行为空

所以我想要的是,如果其中任何一行有无效数据,那么excel就不应该被上传

我尝试了下面的代码,但它只检查第一行,不检查其他两行,然后上传。请帮忙

public void UploadHotoExcel()
{
HttpPostedFile=fluHotoUpload.PostedFile;
byte[]document=新字节[file.ContentLength];
file.InputStream.Read(文档,0,file.ContentLength);
System.UInt32 mimetype;
FindMimeFromData(0,null,document,256,null,0,out-mimetype,0);
System.IntPtr mimeTypePtr=新的IntPtr(mimetype);
字符串mime=Marshal.PtrToStringUni(mimeTypePtr);
FreeCoTaskMem元帅(mimetypter);
字符串类型=string.Empty;
字符串扩展名=Path.GetExtension(file.FileName);
如果(!fluHotoUpload.HasFile)
{
string script=“警报(\”请选择文件。!\”;”;
RegisterStartupScript(this,GetType(),“ServerControlScript”,script,true);
}
else if(fluHotoUpload.HasFile)
{
交换机(分机)
{
案例“.xlsx”:
type=“application/vnd.openxmlformats officedocument.spreadsheetml.sheet”;
打破
案例“.xls”:
type=“application/vnd.openxmlformats officedocument.spreadsheetml.sheet”;
打破
}
if(type!=string.Empty)
{
字符串conStr=“”;
字符串文件名=Path.GetFileName(fluHotoUpload.filename);
字符串filename without rext=“”;
filenamewithoutrext=Path.GetFileNameWithoutExtension(fluHotoUpload.FileName.ToLower();
字符串路径=Server.MapPath(“UploadHoto\\”;
字符串filename_u2;=没有rext的文件名;
if(!Directory.Exists(path))//检查文件夹是否存在。如果不存在,请创建一个新文件夹。
{
CreateDirectory(路径);
}
其他的
{
foreach(Directory.GetFiles(path)中的字符串文件)
{
文件。删除(文件);
}
}
字符串名称;
FhotName=路径+文件名+扩展名;
fluHotoUpload.SaveAs(fhotoName);
HttpContext.Current.Session[“ExcelFilePath”]=FhotName;
System.Data.DataTable dtExcelRows=新的System.Data.DataTable();
交换机(分机)
{
案例“.xls”://Excel 97-03
//conStr=System.Configuration.ConfigurationManager.ConnectionString[“Excel03ConString”].ConnectionString;
conStr=System.Configuration.ConfigurationManager.ConnectionString[“Excel07ConString”].ConnectionString;
打破
案例“.xlsx”://Excel 07
conStr=System.Configuration.ConfigurationManager.ConnectionString[“Excel07ConString”].ConnectionString;
打破
}
conStr=String.Format(conStr,fhotoName,“是”);
System.Data.OleDb.OleDbConnection connExcel=新的System.Data.OleDb.OleDbConnection(conStr);
System.Data.OleDb.OleDbCommand cmdExcel=新的System.Data.OleDb.OleDbCommand();
System.Data.OleDb.OleDbDataAdapter oda=新的System.Data.OleDb.OleDbDataAdapter();
cmdExcel.Connection=connExcel;
Open();
System.Data.DataTable dtExcelSchema=connExcel.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables,null);
System.Data.DataTable dtExcelColumnsTable=connExcel.GetSchema(“列”);
string SheetName=dtExcelSchema.Rows[0][“TABLE_NAME”].ToString().Replace('\'',).Trim();//nadeem
cmdExcel.CommandText=“从[”+SheetName+“]”中选择*;
oda.SelectCommand=cmdExcel;
oda.填充(行);
connExcel.Close();
字符串strInvalidSapID=“”;
字符串strInvalidState=“”;
如果(!dtExcelRows.Columns.Contains(“更新状态”)&&!dtExcelRows.Columns.Contains(“IP非IP站点”)//于2014年9月4日添加
添加(“更新的_状态”,typeof(string));
添加(“IP_非IP_站点”,typeof(string));
DataTable dtStatus=新DataTable();
DataTable dtIPStatus=新DataTable();
string strFlag=string.Empty;
字符串strFlagStatus=“”;
如果(dtExcelRows!=null&&dtExcelRows.Rows.Count>0)
{
DataTable dtDuplicate=新DataTable();
dtDuplicate=dtExcelRows.DefaultView.ToTable(true,“当前SAPID”);
if(dtExcelRows.Rows.Count==dtDuplicate.Rows.Count)
{
for(int i=0;i