【问题标题】:how to use array as parameter in sqldatareader如何在sqldatareader中使用数组作为参数
【发布时间】:2012-01-21 08:59:19
【问题描述】:

我想在 sqldatareader 对象中使用数组。

代码

for(int j=0;j<12;j++)   //12 use for month
 {
  if(j!=(mon-1))
   {
   ***String mont = MyReader1["('"+month[j]+"')"].ToString();***
   tt += mont;
   }
 }

我遇到了类似的错误

'January' System.IndexOutOfRangeException: 'January'

我在数组中使用月份名称

并且在数据库中月份名称是列名

我在 MyReader1["('"+month[j]+"')"]

中有错误

【问题讨论】:

  • 请向我们展示表结构 - 列名和数据类型。

标签: asp.net sql ado.net sqldatareader


【解决方案1】:

如果月份是一个字符串数组,那么试试,

string month=MyReader1[month[j]];

【讨论】:

    猜你喜欢
    • 2012-11-18
    • 2017-11-29
    • 2010-11-04
    • 1970-01-01
    • 2018-12-02
    • 2020-01-09
    • 1970-01-01
    • 2013-10-31
    • 2020-03-13
    相关资源
    最近更新 更多