dao类
       public static Drop_news selectDrop_newsById(int id)
       {
           Drop_news student = null;
           string sql = "select * from Drop_news where Idd=@id";
           using (SqlDataReader re = SqlHelper.ExecuteDataReader(sql, new SqlParameter("@id",id)))
           {
               try
               {
                   if (re.Read())
                   {
                       Drop_news drop = new Drop_news();
                       drop.Id = (Int32)re["idd"];
                       drop.Project = re["Project"].ToString();
                       drop.Voucher_ID = re["Voucher_ID"].ToString();
                       drop.Summary = re["Summary"].ToString();
                       drop.Accountant = (decimal)re["Accountant"];
                       drop.Pay_cash = (decimal)re["Pay_cash"];
                       drop.Surplus_cash = (decimal)re["Surplus_cash"];
                       drop.Total = (decimal)re["Total"];
                       drop.Data = Convert.ToDateTime(re["data"]);
                   }
               }
               catch (Exception ex)
               {
                   Console.WriteLine(ex.Message);
                   return null;
               }
               finally
               {
                   if (re != null)
                       re.Close();
               }
           }
           return  student;
       }
BLLie类  public static Drop_news selectDrop_newsManagerById(int droptid)
      {
          return DAL.Drop_newServer.selectDrop_newsById(droptid);
      }
绑定。。//根据ID查询出来绑定
    //public void bingid(int droptId)
    //{
    //    try
    //    {    //        Drop_news drop = BLL.Drop_newManager.selectDrop_newsManagerById(droptId);
    //        //this.txtid.Text =(drop.Id);
    //        this.txtProje.Text = drop.Project;
    //        this.txtping_id.Text = drop.Voucher_ID;
    //        this.txtzhai.Text = drop.Summary;
    //        //this.txtHui.Text = drop.Accountant;
    //        //this.txtshou.Text = drop.Pay_cash;
    //        //this.txtfu.Text = drop.Surplus_cash;
    //        //this.txtjie.Text = drop.Total;
    //        this.txtdata.Text = drop.Data.ToString("yyyy-MM-dd");
    //    }
    //    catch(Exception ex)
    //    {
    //        Console.WriteLine(ex.Message);
    //    }
    //}

解决方案 »

  1.   

    select * from Drop_news where Idd=@id你这个sql语句是不是写错了!select * from Drop_news where Idd=@id
      

  2.   

    Drop_news student = null; 
    return  student; //这里的值哪来的??如果是这样你应该更改为reutrn drop;// Drop_news drop = new Drop_news(); 
      

  3.   

     
    //更改成这样!!
    public static Drop_news selectDrop_newsById(int id) 
          { 
              //Drop_news student = null;
                Drop_news drop=null; 
              string sql = "select * from Drop_news where Idd=@id"; 
              using (SqlDataReader re = SqlHelper.ExecuteDataReader(sql, new SqlParameter("@id",id))) 
              { 
                  try 
                  { 
                      if (re.Read()) 
                      { 
                          drop = new Drop_news(); 
                          drop.Id = (Int32)re["idd"]; 
                          drop.Project = re["Project"].ToString(); 
                          drop.Voucher_ID = re["Voucher_ID"].ToString(); 
                          drop.Summary = re["Summary"].ToString(); 
                          drop.Accountant = (decimal)re["Accountant"]; 
                          drop.Pay_cash = (decimal)re["Pay_cash"]; 
                          drop.Surplus_cash = (decimal)re["Surplus_cash"]; 
                          drop.Total = (decimal)re["Total"]; 
                          drop.Data = Convert.ToDateTime(re["data"]); 
                      } 
                  } 
                  catch (Exception ex) 
                  { 
                      Console.WriteLine(ex.Message); 
                      return null; 
                  } 
                  finally 
                  { 
                      if (re != null) 
                          re.Close(); 
                  } 
              } 
              return  drop; 
          } 
      

  4.   


    sql没有写错 是这样的 那我先试下该的