【问题标题】:vb.net use lambda to insert to specific columnvb.net 使用 lambda 插入特定列
【发布时间】:2015-02-21 20:38:00
【问题描述】:

我有一个按名称包含所有州的数据库,例如:伊利诺伊州、印第安纳州等。

ID 伊利诺伊州印第安纳州

我想只在其中一列中插入一个新行和一个数字。我有一个变量,我想通过它查找一列(变量 = 列名),然后只在该列中插入一些内容。

这可能吗?

类似于下面的内容...但我不能使用字符串来标识列,因为我想在下面...

Dim obj As New DataClassesDataContext
Dim statesdb As New StatesDb

statesdb.("Illinois") = "12345"   //this is where I would like to use my         dynamic variable and save the data only into that particular column/state.

obj.StatesDb.InsertOnSubmit(statesdb)

【问题讨论】:

    标签: asp.net-mvc vb.net lambda


    【解决方案1】:

    我看到了两种解决方案。

    1. 切换到旧式数据集
    2. 使用反射设置属性值。请参阅MSDN 中的参考资料

    在你的例子中

    'Get the type and PropertyInfo. 
    Dim myType As Type = StatesDb.GetType()
    Dim pinfo As PropertyInfo = myType.GetProperty("Illinois")
    pinfo.SetValue(statesdb, "12345", Nothing)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-10
      • 2016-08-02
      • 1970-01-01
      • 2016-10-21
      • 2015-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多