opcommand.Connection.Open();
你没把 connection 赋值给conmand 你open有啥用SqlDataAdapter myadaddd = new SqlDataAdapter("fwzx", userConnection);
你前面用的 command 没赋值给 DataAdapter

解决方案 »

  1.   

    SqlConnection userConnection = Conn.getConnetion();
    SqlCommand opcommand = new SqlCommand("fwzx", userConnection);
    在这里不是赋值吗
      

  2.   

    SqlDataAdapter myadaddd = new SqlDataAdapter("fwzx", userConnection);
    改为
    SqlDataAdapter myadaddd = new SqlDataAdapter(opcommand);
    就可以啊,原因是SqlDataAdapter没有和SqlCommand关联
      

  3.   


    SqlConnection userConnection = Conn.getConnetion();
    SqlDataAdapter myadaddd = new SqlDataAdapter("fwzx", userConnection);
    myadaddd.SelectCommand.CommandType=CommandType.StoredProcedure;
    SqlParameter fwzx=new Sql....("@fwzx2",SqlDbType.Varchar,50);
    fwzx.Value="xxx";
    DataSet ds=new DataSet();
    myadaddd.SelectCommand.Paramters.Add(fwzx);
    myadaddd.Fill(ds);
    GridView1.DataSource = ds.Tables[0].DefaultView;
    GridView1.DataBind();
      

  4.   

    SqlConnection userConnection = Conn.getConnetion();
    SqlCommand opcommand = new SqlCommand("fwzx", userConnection);
    opcommand.CommandType = CommandType.StoredProcedure;
    opcommand.Parameters.Add("@fwzx2", SqlDbType.VarChar, 50);
    opcommand.Parameters["@fwzx2"].Value = DropDownList1.SelectedItem.Text;
    opcommand.Connection.Open();
    DataSet mydsddd = new DataSet();
    mydsddd.Clear();
    SqlDataAdapter myadaddd = new SqlDataAdapter();
    myadaddd.SelectCommand = opcommand 
    myadaddd.Fill(mydsddd);
    GridView1.DataSource = mydsddd.Tables[0].DefaultView;
    GridView1.DataBind();
    opcommand.Connection.Dispose();
    opcommand.Connection.Close();