string yundan = Convert.ToString(tbyunsuid.Text);
        string jine = Convert.ToString(tbhuowujine.Text);
        int biaozhi = Convert.ToInt32(style.scr("select 标志 from 更新标志表 "));
                if (biaozhi == 1)
        {
            Response.Write("<script>alert('正在更新中,请稍候查询!!')</script>");
        }
        else
        {
                string sql = "select 代收货款,实收总额,退货金额,备注 from 到款登记表 where 运单号='" + yundan + "'";
                if (style.img(sql) == true)
                {
                    string que = "select 运单号,代收货款,实收总额,退货金额,备注 from 到款登记表 where 运单号='" + yundan + "' and Convert(varchar,代收货款)='" + jine + "'";                    if (style.img(que) == true)
                    {
                        gvhkcx.DataSource = style.ds(que);
                        gvhkcx.DataBind();                    }
                    else
                    {
                        string moneyeo = style.scr("select 代收货款 from 到款登记表 where 运单号='" + yundan + "'");
                        Panel1.Visible = true;
                        Label1.Text = "客户要求是:" + moneyeo;
                    }                }
                else
                {
                    Panel1.Visible=true;
                    Label1.Text = "没有"+yundan+"运单号!";
                }
            }
总是提示没有实例化!
public static bool img(string str)
    {//根据传来的条件查询该项是否有内容,有就返回true
        SqlConnection con = style.con();
        con.Open();
        SqlCommand cmd = new SqlCommand(str, con);
        if (cmd.ExecuteScalar().ToString() != "")
            return true;
        else
            return false;
        con.Close();
    }

解决方案 »

  1.   

    SqlConnection con = style.con("连接语句"); 
    con.Open(); 
      

  2.   

    如果连接语句没问题,看看
    cmd.ExecuteScalar()  是不是返回 null 了。
      

  3.   

    public static bool img(string str) 
        {//根据传来的条件查询该项是否有内容,有就返回true 
            SqlConnection con = style.con(); 
            con.Open(); 
            SqlCommand cmd = new SqlCommand(str, con); 
            if (cmd.ExecuteScalar().ToString() != "") 
                return true; 
            else 
                return false; 
            con.Close(); 
        }
    这个就有问题,怎么把colse()写到 return后边了?
      

  4.   


    string yundan = Convert.ToString(tbyunsuid.Text); 
            string jine = Convert.ToString(tbhuowujine.Text); 
            int biaozhi = Convert.ToInt32(style.scr("select 标志 from 更新标志表 ")); 
                    if (biaozhi == 1) 
            { 
                Response.Write(" <script>alert('正在更新中,请稍候查询!!') </script>"); 
            } 
            else 
            { 
                    string sql = "select 代收货款,实收总额,退货金额,备注 from 到款登记表 where 运单号='" + yundan + "'"; 
                    if (style.img(sql) == true) 
                    { 
                        string que = "select 运单号,代收货款,实收总额,退货金额,备注 from 到款登记表 where 运单号='" + yundan + "' and Convert(varchar,代收货款)='" + jine + "'";                     if (style.img(que) == true) 
                        { 
                            gvhkcx.DataSource = style.ds(que); 
                            gvhkcx.DataBind();                     } 
                        else 
                        { 
                            string moneyeo = style.scr("select 代收货款 from 到款登记表 where 运单号='" + yundan + "'"); 
                            Panel1.Visible = true; 
                            Label1.Text = "客户要求是:" + moneyeo; 
                        }                 } 
                    else 
                    { 
                        Panel1.Visible=true; 
                        Label1.Text = "没有"+yundan+"运单号!"; 
                    } 
                } 
    public static bool img(string str) 
        {//根据传来的条件查询该项是否有内容,有就返回true 
            SqlConnection con = style.con(); 
            con.Open(); 
            SqlCommand cmd = new SqlCommand(str, con); 
            if (cmd.ExecuteScalar().ToString() != "") 
                return true; 
            else 
                return false; 
            con.Close(); 
        }
      

  5.   

    不知楼猪是否知道VS IDE有 行号 这个功能