检测到不可解释的表达式代码。 [英] unreacheble expression code detected.

查看:91
本文介绍了检测到不可解释的表达式代码。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行调试器时,我收到警告检测到无法访问的表达式代码,我似乎无法理解为什么。你能帮我吗?警告遍布所有!String.IsNullOrEmpty(Firstname.Text)



when I run the Debugger i get the warning "unreachable expression code detected" and I can´t seem to understand why. Can u help me? the warnings are over all of the "!String.IsNullOrEmpty(Firstname.Text)"

void anv() 
{
SqlCommand CMD_Select = new SqlCommand("SELECT ID,MailAdress,TagID FROM Users WHERE   TagID ='"+TagID.Text+"' AND Active = '1'", MyConnection;
MyConnetction.Open();
SqlDataReader DR_Select = CMD_Select.ExecuteReader();
while (DR_Select.Read())
  {
    infofinns = true;
  }
  if (infofinns == ture)
  {
    lbl_Tag-Visible = true;
  }
  else
  {
  lbl_Tag.Visible = false;
  }
  MyConnection.Close();

  if (lbl_Tag.Visible = false && !String.IsNullOrEmpty(Firstname.Text) && !String.IsNullOrEmpty(Lastname.Text) && !String.IsNullOrEmpty(Email.Text) && !String.IsNullOrEmpty(TagID.Text))
  {
SqlCommand CMD_Insert_user = new SqlCommand("INSERT INTO Users (Firstname,    Lastname, MailAdress, TagID, Active) VALUES ('" + Firstname.Text + "','" + Lastname.Text + "','" + Email.Text + "','" + TagID.Text + "','1')", MyConnection);
   MyConnection.Open();
   CMD_Insert_user.ExecuteNonQuery();
   MyConnection.Close();
   lbl_ny_elev.Visible = true;
  }
  else
  {
   lbl_ny_elev.visible = false;
  }
}

推荐答案

问题出在行中
if (lbl_Tag.Visible = false ...

它应该开始

if (lbl_Tag.Visible == false ...





实际上不需要包含 == false - 而是使用

if (!lbl_Tag.Visible





此代码还有其他几个问题 - 它实际上不会编译,直到你摆脱所有的拼写错误,例如



There are several other problems with this code - it won't actually compile until you get rid of all of the spelling errors e.g.

if (infofinns == ture)

应该是

if (infofinns)

还是 MyConnection MyConnetction


嗯...我认为这是你遇到的最少的问题。



1) true 拼写不是ture

2)这段代码应该做什么:

Um...I think that's the least of your problems.

1) true is not spelled "ture"
2) What is this code supposed to do:
while (DR_Select.Read())
  {
    infofinns = true;
  }



3)这是什么:


3) What is this:

lbl_Tag-Visible = true;

您的意思是

Did you mean

lbl_Tag.Visible = true;

如果是这样,为什么要有if?

4)不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。改为使用参数化查询。



说真的,从编译列表中的第一个错误开始,然后在转到下一个错误之前进行处理:并在你的时候理清你的缩进让它编译!

If so, why have an if at all?
4) Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

Seriously, start with the first error in your compilation list, and work on that before moving to the next: and sort out your indentation when you get it to compile!


这篇关于检测到不可解释的表达式代码。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆