问题描述
usingSystem;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.IO;publicpartialclassTreeSpotRemark:System.Web.UI.Page{SqlDateMyCon=newSqlDate();protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){SqlConnectionSqlCon=MyCon.GetCon();SqlCon.Open();stringstrCollectLocus=Page.Request.QueryString["CollectLocus"];//Response.Write(strCollectLocus);stringStrSql="selectt1.TreeChineseName,t1.TreeLatinName,t1.ItemPreside,t1.CollectIntention,t1.CollectPeople,t1.CollectTime,t1.CollectLocus,t1.CollectSwatchId,t1.Height,t1.MeasurePeople,t1.AcrossPeople,t1.DataAnalyse,t1.AgeLength,t1.ReferenceArticle,t3.TreeTime,t3.TreeIndices,t3.TreeNumber,t3.TreeTypefromTreeAgeDateRemarkt1,TreeAgeDatat3wheret1.CollectLocus=t3.CollectLocusand(CollectLocus='"+strCollectLocus+"')";SqlDataAdapterSda=newSqlDataAdapter(StrSql,SqlCon);DataSetMyds=newDataSet();Sda.Fill(Myds,"datatable");DataRowViewmydrv=Myds.Tables["datatable"].DefaultView[0];TxtBChinanNme.Text=Convert.ToString(mydrv.Row["TreeChineseName"]);TxtBLtName.Text=Convert.ToString(mydrv.Row["TreeLatinName"]);TxtBItemMan.Text=Convert.ToString(mydrv.Row["ItemPreside"]);TxtBAim.Text=Convert.ToString(mydrv.Row["CollectIntention"]);TxtBPeople.Text=Convert.ToString(mydrv.Row["CollectPeople"]);TxtBGatherTime.Text=Convert.ToString(mydrv.Row["CollectTime"]);TxtBArea.Text=Convert.ToString(mydrv.Row["CollectLocus"]);TxtBCode.Text=Convert.ToString(mydrv.Row["CollectSwatchId"]);TxtBHeight.Text=Convert.ToString(mydrv.Row["Height"]);TxtBMeasureMan.Text=Convert.ToString(mydrv.Row["MeasurePeople"]);TxtBCrossMan.Text=Convert.ToString(mydrv.Row["AcrossPeople"]);TxtBFxMan.Text=Convert.ToString(mydrv.Row["DataAnalyse"]);TxtBYearLen.Text=Convert.ToString(mydrv.Row["AgeLength"]);TxtBArticle.Text=Convert.ToString(mydrv.Row["ReferenceArticle"]);}}}点A.aspx中的GRIDVIEW中显示的地点项后,链接到B.aspx(在这页中显示详细信息)TreeAgeDateRemark表和TreeAgeData表有共同项CollectLocus,运行后总提示:列名‘CollectLocus’不明确,为什么啊?
解决方案
解决方案二:
CollectLocus前面要加上限定符,比如:t1.CollectLocus或t3.CollectLocus因为t1,t3中都有这个字段,所以系统不知道你指的是哪一个。
解决方案三:
你是不是有多个CollectLotus列?
解决方案四:
没有啊,一个表里就一个CollectLotus列,我改为t1.CollectLocus后再运行,报“索引0不是为负数就是大于行数”请大家再指点一下
解决方案五:
要判断记录是否为空
解决方案六:
在sql里把CollectLotus列as成其他名式一下
解决方案七:
sql语句试了可以的,在这地方DataRowViewmydrv=Myds.Tables["datatable"].DefaultView[0];报“索引0不是为负数就是大于行数”,我试了,如果把两个表合成一个数据表就是可以的,请大家看看这句那里不对啊