private bool checkcount()  //判断数量中是否存在负数,以确定是否要开清单
{
SqlConnection con=new SqlConnection("server=localhost;database=ufdata-excel;uid=sa;pwd=luohzh");
SqlDataAdapter com=new SqlDataAdapter(strsql,con);
DataSet dsmul_count=new DataSet();
com.Fill(dsmul_count,"mult_table_count");
this.dataGrid1.DataSource=dsmul_count.Tables[0].DefaultView;
int crowscount=dsmul_count.Tables[0].Rows.Count;
int aaa;
if (crowscount>1)
{
for (int i=0;i<crowscount;i++)
{
aaa=int.Parse(this.dataGrid1[i,3].ToString());
if (aaa<=0)
{   this.btnpritqd.Enabled=false;
MessageBox.Show("发货数量中存在负数,请先开发票后再开清单!","出错信息",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox1.Focus();
                                     return false;}
}
}请赐教......

解决方案 »

  1.   

    你那个if... return false;
    应该没个分支都有返回直,如:
    if(..)
       {
       ...
       return false;
    }
    return true;
      

  2.   

    你这根本不是构造函数,就是一个标准函数。出问题是因为你的程序中不是所有分支(条件语句)都有返回值,你考虑问题不全面,漏掉了else时的返回值。
      

  3.   

    Private bool checkcount()  
    {
    SqlConnection con=new SqlConnection("server=localhost;database=ufdata-excel;uid=sa;pwd=luohzh");
    SqlDataAdapter com=new SqlDataAdapter(strsql,con);
    DataSet dsmul_count=new DataSet();
    com.Fill(dsmul_count,"mult_table_count");
    this.dataGrid1.DataSource=dsmul_count.Tables[0].DefaultView;
    int crowscount=dsmul_count.Tables[0].Rows.Count;
    int aaa;
    if (crowscount>1)
    {
    for (int i=0;i<crowscount;i++)
    {
    aaa=int.Parse(this.dataGrid1[i,3].ToString());
    if (aaa<=0)
    {
    this.btnpritqd.Enabled=false;
    MessageBox.Show("发货数量中存在负数,请先发票后再开清单!","出错信息",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
    this.textBox1.Focus();
    return false;
    }
    else {return true;}
    }
      }
    }
    老兄们加了else的返回值结果还是一样?
    why?
      

  4.   

    luohzad(一心一意想成为c#高手) :
    你的问题可以简单描述成这样:if (crowscount>1)
    {
       if (aaa<=0)
        { return false;}
       else
        { return ture;}
    }显然当(crowscount>1)不成立时,还是没有返回的.