none
DropDownList.SelectedValue.ToString() 和Sql Server 的问题,请给位前辈帮忙看一下错误的原因吧, RRS feed

  • 问题

  • else
            {
                Session["SearchStr"] = "select ST1.*,ST2.*,DT.DepartID,DT.DepartName,ST.SpecialtyID,ST.SpecialtyName,GT.GradeID,GT.GradeName,CT.ClassID,CT.ClassName,SD.DutyName from DepartTable as DT,SpecialtyTable as ST,GradeTable as GT,ClassTable as CT,StudentDuty as SD ,StudentTable as ST1,SchoolTable as ST2 where ST2.SchoolID  =DT.SchoolID and DT.DepartID=ST.DepartID and CT.GradeID =GT.GradeID and ST.SpecialtyID=CT.SpecialtyID and CT.ClassID=ST1.ClassID and ST1.DutyID=SD.DutyID";
                if (DropDownList1.SelectedValue.ToString() != "")
                {
                    SchoolStr = "and SchoolTable.SchoolID='" + DropDownList1.SelectedValue.ToString()+"'";
                    Session["SearchStr"] = Session["SearchStr"] + SchoolStr;

                   //运行时,总是出现数据库错误,错误原因:第 1 行: 'SchoolTable' 附近有语法错误。
                    if (DropDownList2.SelectedValue.ToString() != "")
                    {
                        DepartStr = "and DepartTable.DepartID='" + DropDownList2.SelectedValue.ToString()+"'";
                        Session["SearchStr"] = Session["SearchStr"] + DepartStr;
                        if (DropDownList3.SelectedValue.ToString() != "")
                        {
                            SpecialStr = "and SpecialtyTable.SpecialtyID='" + DropDownList3.SelectedValue.ToString()+"'";
                            Session["SearchStr"] = Session["SearchStr"] + SpecialStr;
                            if (DropDownList4.SelectedValue.ToString() != "")
                            {
                                GradeStr = "and GradeTable.GradeID='" + DropDownList4.SelectedValue.ToString()+"'";
                                Session["SearchStr"] = Session["SearchStr"] + GradeStr;
                            }
                            if (DropDownList5.SelectedValue.ToString() != "")
                            {
                                ClassStr = "and ClassTable.ClassID='" + DropDownList5.SelectedValue.ToString()+"'";
                                Session["SearchStr"] = Session["SearchStr"] + ClassStr;
                            }
                            if (DropDownList6.SelectedValue.ToString() != "")
                            {
                                DutyStr = "and StudentDuty.DutyID='" + DropDownList6.SelectedValue.ToString()+"'";
                                Session["SearchStr"] = Session["SearchStr"] + DutyStr;
                            }
                        }
                    }
                }
            }



     Session["SearchStr"] = "select ST1.*,ST2.*,DT.DepartID,DT.DepartName,ST.SpecialtyID,ST.SpecialtyName,GT.GradeID,GT.GradeName,CT.ClassID,CT.ClassName,SD.DutyName from DepartTable as DT,SpecialtyTable as ST,GradeTable as GT,ClassTable as CT,StudentDuty as SD ,StudentTable as ST1,SchoolTable as ST2 where ST2.SchoolID  =DT.SchoolID and DT.DepartID=ST.DepartID and CT.GradeID =GT.GradeID and ST.SpecialtyID=CT.SpecialtyID and CT.ClassID=ST1.ClassID and ST1.DutyID=SD.DutyID";这个是没有错误的,我在SQL查询分析器中已经运行过了!

    2010年2月1日 9:22

答案

全部回复