问题描述
我在项目中定义了一个类:GetValue.csusingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceDzCaiZheng{publicclassGetValue{publicstringexeclFileName;publicstringexeclFile{get{returnexeclFileName;}set{execlFileName=value;}}}}在B窗体中引用:GetValuegetValue=newGetValue();getValue.execlFileName=File_Path.Text;在A窗体引用B体窗中获得的值:GetValuegetValue=newGetValue();stringExeclname=getValue.execlFileName;为什么取不到值呢哪位高手能指点一下,给出在A窗体中的正确调用方式另外,下面加红的地方,动态取得一个EXECL的路径这样写是否正确.DataSource=@Execlname这句是否正确if(Execlname!=null){OleDbConnectionoledbConn=newOleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;PersistSecurityInfo=False;ExtendedProperties=Excel8.0;DataSource=@Execlname;");OleDbCommandcmd=newOleDbCommand("select*fromcz2007",oledbConn);OleDbDataAdapteradp=newOleDbDataAdapter(cmd);DataSetds=newDataSet();adp.Fill(ds);}
解决方案
解决方案二:
第一个问题,要把execlFileName属性改成一个静态属性
解决方案三:
publicclassGetValue{publicstaticstringexeclFileName;publicstaticstringexeclFile{get{returnexeclFileName;}set{execlFileName=value;}}}