声明的结尾给出了两个分号,但它们没有引起错误。 [英] End of the statement given a two semicolon but they are no raising errors.

查看:87
本文介绍了声明的结尾给出了两个分号,但它们没有引起错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public   string  DoInsertTravels(字符串 proc,字符串 travelsname)
{
尝试
{
mDbconnection = conn.GetDefaultDbConnectionString();
使用(SqlCommand cmd = new SqlCommand(proc,mDbconnection))
{
string 结果= string .Empty;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add( @ Travelsname,SqlDbType.NVarChar, 150 )。Value = travelsname;
cmd.Parameters.Add( @ Result,SqlDbType.NVarChar, 500 )。Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
返回结果= cmd.Parameters [ @结果] Value.ToString(); ;
}
}
catch { throw ; }
finally
{
mDbconnection.Close();
}
}

解决方案

你不应该这样做,但也不应该造成任何伤害。围绕它的一个很好的讨论就在这里, http://stackoverflow.com/questions/4790771/does-c-sharp-allow-double-semicolon-if-so-are-there-any-special-ways [ ^ ]

public string DoInsertTravels(string proc,string travelsname)
      {
          try
          {
              mDbconnection = conn.GetDefaultDbConnectionString();
              using (SqlCommand cmd = new SqlCommand(proc, mDbconnection))
              {
                  string Result = string.Empty;
                  cmd.CommandType = CommandType.StoredProcedure;
                  cmd.Parameters.Add("@Travelsname", SqlDbType.NVarChar, 150).Value = travelsname;
                  cmd.Parameters.Add("@Result", SqlDbType.NVarChar, 500).Direction = ParameterDirection.Output;
                  cmd.ExecuteNonQuery();
                  return Result = cmd.Parameters["@Result"].Value.ToString(); ;
              }
          }
          catch { throw; }
          finally
          {
              mDbconnection.Close();
          }
      }

解决方案

You shouldn't do it but it also should not do any harm. A good discussion around it is located here, http://stackoverflow.com/questions/4790771/does-c-sharp-allow-double-semicolon-if-so-are-there-any-special-ways[^]


这篇关于声明的结尾给出了两个分号,但它们没有引起错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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