我通過以下的代碼得到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();
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();
XmlNode node = xml.SelectSingleNode("//root/MAC_ADDRESS");
if (node != null)
{
mymac = node.InnerText.ToUpper();
}if (String.IsNullOrEmpty(mymac))
{
//不为空
}
if (String.IsNullOrEmpty(mymac))
{
//为空
}
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 ){}顯示錯誤,有沒有別的辦法當我條件不存在時就顯示就查詢是空值?
這句話其實已經返回了查詢的值了,我是想判斷要查詢mac的值是否為空?
哪要增加一個判斷這個的代碼,判斷是否可以執行?
{
不空
}
else
{
空
}
if(mac !=s tring.Empty)
{
不空
}
else
{
空
}
if(mac !=string.Empty)
{
不空
}
else
{
空
}看看行不
我是想當我輸入條件不存在時,就告訴用戶用條件是空的
string mac = ft.GetMAC(s.ToUpper());
你的mac是从数据库里面查出来的?那你就用String.IsNullOrEmpty(mac)来判断呗
如果为空,就不要用Xml.Load了
{
ss = node.InnerText.ToUpper();
MessageBox.Show(ss);
}
if(String.IsNullOrEmpty(ss))
{
MessageBox.Show("NG");
}
你把这东西放在catch里判断
{
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;
}
}