public class aa
{
public string c1;
public string c2;
public string c3;
public string c4;
public string c5;
public string c6;
}
public static bool haha()
{
string PriceID = String.Empty;
SqlConnection con = showclass.datacon.AutoCon();
con.Open();
SqlCommand cmd = new SqlCommand("cc_cc " + PriceID,con);
aa PV=new aa();
using(SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
if(sdr.Read())
{
PV.c1 = sdr["auto_price"].ToString();
PV.c2 = sdr["auto_color"].ToString();
PV.c3 = sdr["user_dw"].ToString();
PV.c4 = sdr["user_tel"].ToString();
PV.c5 = sdr["AutoBrand"].ToString();
PV.c6 = sdr["AutoType"].ToString();
}
}
con.Close();
}
这个类那里写的不对!
然后在别的页面如何调用?

解决方案 »

  1.   

    public static bool haha() 
    这个地方不对!
      

  2.   

    C:\Inetpub\wwwroot\AutoColumns\Demonstration\cc.cs(27): “AutoColumns.Demonstration.cc.haha()” : 并非所有的代码路径都返回值
      

  3.   

    public static bool haha()需要返回bool 型结果
    你的haha()方法内的所有分支都要返回一个true或false;
    如:
    public static bool haha()
    {
    string PriceID = String.Empty;
    SqlConnection con = showclass.datacon.AutoCon();
    con.Open();
    SqlCommand cmd = new SqlCommand("cc_cc " + PriceID,con);
    aa PV=new aa();
    using(SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
    {
    if(sdr.Read())
    {
    PV.c1 = sdr["auto_price"].ToString();
    PV.c2 = sdr["auto_color"].ToString();
    PV.c3 = sdr["user_dw"].ToString();
    PV.c4 = sdr["user_tel"].ToString();
    PV.c5 = sdr["AutoBrand"].ToString();
    PV.c6 = sdr["AutoType"].ToString();
    }
    }
    con.Close();
    return true;
    }
      

  4.   

    public class aa
    {
    public string c1;
    public string c2;
    public string c3;
    public string c4;
    public string c5;
    public string c6; public static bool haha()
    {
    string PriceID = String.Empty;
    SqlConnection con = showclass.datacon.AutoCon();
    con.Open();
    SqlCommand cmd = new SqlCommand("cc_cc " + PriceID,con);
    aa PV = new aa();
    using(SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
    {
    if(sdr.Read())
    {
    PV.c1 = sdr["auto_price"].ToString();
    PV.c2 = sdr["auto_color"].ToString();
    PV.c3 = sdr["user_dw"].ToString();
    PV.c4 = sdr["user_tel"].ToString();
    PV.c5 = sdr["AutoBrand"].ToString();
    PV.c6 = sdr["AutoType"].ToString();
    }
    }
    con.Close();
    return true; //反正最后你的有返回值啊
    }
    }
      

  5.   

    改为void
    public static void haha()
      

  6.   

    还有楼主你的命名不规范,类名应该是大写字母开头,方法名在.NET中也是大写字母开头
      

  7.   

    SqlCommand cmd = new SqlCommand("cc_cc " + PriceID,con);
    这句话有问题开始的帖子已经告诉你怎么做了
      

  8.   

    SqlCommand cmd = new SqlCommand("cc_cc " + PriceID,con);
    这个地方已经OK了
      

  9.   

    改为void
    public static void haha()
    删除void?