Column 'Column Name' does not belong to table Table

 

Server Error in '/WebSite1' Application.


Column '工号' does not belong to table Table.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Column '工号' does not belong to table Table.

Source Error:

Line 65:         foreach (DataRow dataRow in objDs.Tables[0].Rows)
            Line 66:         {
            
Line 67: objKqDatas.Insert(
Line 68:                 objDictionary["PrimaryKey"].ToString(),
            Line 69:                 dataRow["工号"].ToString(),


Source File: d:\Projects\ERP\System\HumanResources\KQ\Analysis.aspx.cs Line: 67

Stack Trace:

[ArgumentException: Column '工号' does not belong to table Table.]
            System.Data.DataRow.GetDataColumn(String columnName) +2079375
            System.Data.DataRow.get_Item(String columnName) +13
            System_HumanResources_KQ_Analysis.Data_Binding() in d:\Projects\ERP\System\HumanResources\KQ\Analysis.aspx.cs:67
            System_HumanResources_KQ_Analysis.Page_Load(Object sender, EventArgs e) in d:\Projects\ERP\System\HumanResources\KQ\Analysis.aspx.cs:34
            System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
            System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
            System.Web.UI.Control.OnLoad(EventArgs e) +91
            System.Web.UI.Control.LoadRecursive() +74
            System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
            

 


 

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

 

用户上传的文件不符合样版文件。列名不一致。需要想出一个方法,去判断Excel的表头字段。下面方法是检查出Excel结构,需要使用GetOleDbSchemaTable方法进行处理。

  // oleDBconnection  http://www.cnblogs.com/insus/articles/2008946.html
         string  ec  =  objKQ.GetExcelConnectionString( " ~/Temp/49be9717-ed46-4f1e-8302-4d23efe4db93.xlsx " );
       
        OleDbConnection oc 
=   new  OleDbConnection(ec);
        oc.Open();
        String[] restrections 
=  {  null null " Sheet1$ " null  };
        DataTable oDt 
=  oc.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,restrections);
        oc.Close();

 

结果:

 

到此为止,只是找到Excel文件的Schema,接下来是需要处理得到的结果是否是您要求的字段了。

 String[] excelColumn  =   new  String[oDt.Rows.Count];
        
int  i  =   0 ;

        
foreach  (DataRow row  in  dt.Rows)
        {
            excelColumn[i] 
=  row[ " COLUMN_NAME " ].ToString();
            i
++ ;
        }

        
for  ( int  j  =   0 ; j  <  excelColumn.Length; j ++ )
        {
            
// 这里比自己的字段。
        }

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值