SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
        con.Open();
        string cmdtext = "select lname from lanmu";
        SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
        DataSet ds = new DataSet();
        sda.Fill(ds, " lname");
        this.DropDownList1.DataSource = ds.Tables["lname"].DefaultView;
        DropDownList1.DataValueField = "lname";
        DropDownList2.DataTextField = "lname";
        DropDownList1.DataBind();
        con.Close();但是总是提示未将对象引用设置到对象的实例。 这哪里错了?

解决方案 »

  1.   

    ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString();
      

  2.   

      //绑定
            string strSQL = "select * from class where parent_ptr="+strId ;
            db d = new db();
            DataTable dt = d.getDT(strSQL);        this.ddl2.DataSource = dt;
            this.ddl2.DataTextField = "classCName";
            this.ddl2.DataValueField = "id";
            this.ddl2.DataBind();
      

  3.   


            DropDownList1.DataValueField = "lname"; 
            DropDownList2.DataTextField = "lname"; // 怎么是2了又
            DropDownList1.DataBind(); 
      

  4.   

    连接字符串 没读到 看看 SQL 配置。
      

  5.   

    字符串读到 SQL 配置了,我调试了,还是提示未将对象引用设置到对象的实例,是说lname字段的问题  想不通了