我通過以下的代碼得到mymac的值。哪我如何判斷我輸入的條件查詢的值是否在數據庫裡存在呢?WS.FTService ft = new Paid_Server.WS.FTService();
                                     ft.Url = smes;
                                     string macXml = ft.GetMAC(sbarcode.ToUpper());
                                     XmlDocument xml = new XmlDocument();
                                     xml.LoadXml(macXml);
                                     string mymac = xml.SelectSingleNode("//root/MAC_ADDRESS").InnerText.ToUpper();

解决方案 »

  1.   

    就是增加一個判斷,如果輸入的條件查詢的值在數據裡存在就告訴用戶ok,如果條件查詢的值不存數據庫裡就告訴用戶false
      

  2.   

    string mymac = xml.SelectSingleNode("//root/MAC_ADDRESS").InnerText.ToUpper();-------------->>string mymac = "";
    XmlNode node = xml.SelectSingleNode("//root/MAC_ADDRESS");
    if (node != null)
    {
        mymac = node.InnerText.ToUpper();
    }if (String.IsNullOrEmpty(mymac))
    {
        //不为空
    }
      

  3.   

    错了
    if (String.IsNullOrEmpty(mymac)) 

        //为空 
    }
      

  4.   

    不行,如果改成這樣:
    try
                {
                    mes.FTService ft = new WindowsApplication7.mes.FTService();
                    string s = textBox1.Text;
                    string mac = ft.GetMAC(s.ToUpper());                              XmlDocument xml = new XmlDocument();
                    xml.LoadXml(mac);
                    string ss = "";
                    XmlNode node = xml.SelectSingleNode("//root/MAC_ADDRESS");
                    if(node != null)
                    {
                        ss = node.InnerText.ToUpper();
                        MessageBox.Show(ss);
                    }
                    if(String.IsNullOrEmpty(ss))
                    {
                        MessageBox.Show("NG");
                    }                
                }
                catch (Exception er)
                {
                    MessageBox.Show(er.Message);
                }
    哪麼當我輸入的條件根本是不存數據庫裡的,也就是我數據庫裡連哪個要查詢的條件都沒有,就會在er.message上顯示錯誤
    我是想不要try()catch(Exception er ){}顯示錯誤,有沒有別的辦法當我條件不存在時就顯示就查詢是空值?
      

  5.   

    想使用if(){}else(){}來判斷是否為空值
      

  6.   

    string mac = ft.GetMAC(s.ToUpper());  
    這句話其實已經返回了查詢的值了,我是想判斷要查詢mac的值是否為空?
    哪要增加一個判斷這個的代碼,判斷是否可以執行?
      

  7.   

    if(ss!=string.Empty)
    {
    不空
    }
    else
    {

    }
      

  8.   


    if(mac !=s tring.Empty) 

    不空 

    else 

    空 
    }
      

  9.   


    if(mac !=string.Empty) 

    不空 

    else 

    空 
    }看看行不
      

  10.   

    不行。如果沒有了try{}catch{}的話,當我輸入的條件在數據庫裡不存在的話,程式出錯,關掉了...
    我是想當我輸入條件不存在時,就告訴用戶用條件是空的
      

  11.   

    你是说
    string mac = ft.GetMAC(s.ToUpper());  
    你的mac是从数据库里面查出来的?那你就用String.IsNullOrEmpty(mac)来判断呗
    如果为空,就不要用Xml.Load了
      

  12.   

    if(node != null)
                    {
                        ss = node.InnerText.ToUpper();
                        MessageBox.Show(ss);
                    }
                    if(String.IsNullOrEmpty(ss))
                    {
                        MessageBox.Show("NG");
                    }                
    你把这东西放在catch里判断
      

  13.   

     public bool CheckSpcTckS2Exist(string p_strpaperkind, string p_strCk_kind)
            {
                try
                {
                    string strSql = "SELECT COUNT(*) FROM spc_Tck_s2 WHERE paperkind='" + p_strpaperkind + "' AND ck_kind  ='" + p_strCk_kind + "'";
                    logger.Debug(strSql);
                    string strResult = helper.GetStr(strSql);
                    logger.Info("读取记录成功!,记录为:   " + strResult);
                    if (Int32.Parse(strResult) > 0)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch (Exception exp)
                {
                    logger.Error("读取记录失败!原因为:   " + exp.ToString());
                    return false;
                }
            }