加入收藏 | 设为首页 | 会员中心 | 我要投稿 我爱资讯网 (https://www.52junxun.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

变量传递给asp.net中的'typeof'运算符

发布时间:2023-02-16 13:25:01 所属栏目:Asp教程 来源:
导读:  本文介绍了变量传递给asp.net中的'typeof'运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

  问题描述

  在belwo代码中,我想归纳"typeof",
  本文介绍了变量传递给asp.net中的'typeof'运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
 
  问题描述
 
  在belwo代码中,我想归纳"typeof",这就是为什么我设计将参数"typ"传递给"typeof"运算符的原因.我没有典型"变量的想法,但它不起作用!所以,我如何概括将要传递给``typeof''运算符的变量,它是什么变量类型!我的代码:
 
  In the belwo code i want to generalize ''typeof'' that''s why i have designed to pass parameter ''typ'' to ''typeof'' operator . I don''t have the idea of ''typ'' variable but it''s not working !!! So, how i can generalized the variable to be passed to ''typeof'' operator and what is it''s variable type !!!! My code :
 
  public static string BuildWhereCondition(Type typ, string columnName, string columnValue)
  {
      string whereCondition = string.Empty;
      PropertyInfo columnInfo = typeof(typ).GetProperty(columnName);
      if (columnInfo != null)
      {
         if (columnInfo.PropertyType == typeof(int))
         {
             whereCondition = columnName + "=" + columnValue;
         }
 
         else if (columnInfo.PropertyType == typeof(String))
         {
             whereCondition = columnName + " LIKE '%" + columnValue + "%'";
         }
         else if (columnInfo.PropertyType == typeof(DateTime))
         {
             whereCondition = columnName + "='" + columnValue + "'";
         }
      }
      return whereCondition;
  }
  在此先谢谢您.
 
  Thanks in advance .
 
  推荐答案 typeof(typ)是Type.试试这个:
 
  The typeof(typ) is Type. Try this:
 
  if(typ.Equals(System.Int)) {
     // ...
  }
  但是,串联sql命令字符串是软件的主要风险.最好将参数添加到SqlCommand.检查以下链接:
 
  [ ^ ]
 
  祝你好运!
 
  However, concatenating sql command strings is a major risk in software. It would be better to add parameters to the SqlCommand. Check the link below:
 
  [^]
 
  Good luck!
 
  阅读此
 
  typeof(c#) [ ^ ] read this
 
  typeof(c#)[^]
 
  这篇关于变量传递给asp.net中的'typeof'运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助ASP 变量,也希望大家多多支持IT屋!
 

(编辑:我爱资讯网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章