源错误: 
行 30: { 
行 31: 
行 32: string sstr1 = Session["drop1"].ToString(); 
行 33: string sstr2 = Session["drop2"].ToString(); 
行 34: string sstr3 = Session["drop3"].ToString(); 堆栈跟踪: 
[NullReferenceException: 未将对象引用设置到对象的实例。] 
HouAdmin_InsertShiTi.btnAdd_Click(Object sender, EventArgs e) in d:\My Documents\Visual Studio 2005\WebSites\WebSite3\HouAdmin\InsertShiTi.aspx.cs:32 
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75 
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +97 
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919 
protected void btnAdd_Click(object sender, EventArgs e) 
{ string sstr1 = Session["drop1"].ToString(); 
string sstr2 = Session["drop2"].ToString(); 
string sstr3 = Session["drop3"].ToString(); 
if (ddlType.SelectedIndex == 0) 

dataconn.eccom("insert into tb_Questions" 
+ "(que_lessonid,que_subject,que_type,optionA,optionB,optionC,optionD,option0,option1,que_answer)" 
+"values('" + sstr1 + "','" + sstr2 + "','" + sstr3 + "','" + this.txtExamTitle.Text 
+ "','" + ddlType.Text + "','" + this.txtExamA.Text + "','" + this.txtExamB.Text 
+ "','" + this.txtExamC.Text + "','" + this.txtExamD.Text + "','" 
+ ddlAnswer.Text + "')"); 
Response.Redirect("kaoshi_timu.aspx"); 

else 
{ if (cblAnswer.Items[0].Selected == true && cblAnswer.Items[1].Selected == false && cblAnswer.Items[2].Selected == false && cblAnswer.Items[3].Selected == false) 

string str1 = "A"; 
dataconn.eccom("insert into tb_Questions" 
+ "(que_lessonid,que_subject,que_type,optionA,optionB,optionC,optionD,que_answer)" 
+"values('" + sstr1 + "','" + sstr2 + "','" + sstr3 + "','" + this.txtExamTitle.Text 
+ "','" + ddlType.Text + "','" + this.txtExamA.Text + "','" + this.txtExamB.Text 
+ "','" + this.txtExamC.Text + "','" + this.txtExamD.Text + "','" + str1 
+ "')"); 他们说我没赋值,请问我应该怎么赋值啊最好告诉我具体的,我是新手

解决方案 »

  1.   

    行 32: string sstr1 = Session["drop1"].ToString(); 
    行 33: string sstr2 = Session["drop2"].ToString(); 
    行 34: string sstr3 = Session["drop3"].ToString(); 没有给session赋值,然后取值,就出错了
    拿一个举例子string sstr1 = null;
    if(Session["drop1"]!=null)
    {
       sstr1 = Session["drop1"].ToString(); 
    }
      

  2.   

    string sstr1 = Session["drop1"].ToString(); 
    string sstr2 = Session["drop2"].ToString(); 
    string sstr3 = Session["drop3"].ToString(); 楼主看看这个有没有赋值过,Session["drop"]=XXX;
    最好是前面加个
    if(Session["drop"]!=null)
    {
    //你的代码
    }
      

  3.   

    编译器错误信息: CS0128: 已在此范围定义了名为“sstr1”的局部变量。源错误: 行 45:             sstr3 = Session["drop3"].ToString();
    行 46:         }
    行 47:         string sstr1 = Session["drop1"].ToString();
    行 48:         string sstr2 = Session["drop2"].ToString();
    行 49:         string sstr3 = Session["drop3"].ToString();
     
      

  4.   

    session应该是没值,你赋值调试一下就清楚了
      

  5.   

    string sstr1 = Session["drop1"]?==null?"":Session["drop1"].ToString(); 
    string sstr2 = Session["drop2"]?==null?"":Session["drop2"].ToString(); 
    string sstr3 = Session["drop3"]?==null?"":Session["drop3"].ToString(); 
      

  6.   

    string sstr1 = Session["drop1"]==null?"":Session["drop1"].ToString();