源数组中至少有一个元素无法转换为目标数组类型。 [英] At least one element in the source array could not be cast down to the destination array type.

查看:363
本文介绍了源数组中至少有一个元素无法转换为目标数组类型。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我有一个名为no()的方法



在该方法中我从数据库中检索qno我必须将这些数字放在整数类型的数组中。

Hi i have a method named no()

in that method i am retrieving the qno from database I have to place those numbers in array of integer type.

public void no()
{
    SqlCommand cmd = new SqlCommand("select qno from QUIZ1 where applicationname = @appname", con);
    cmd.Parameters.AddWithValue("@appname", this.application);
    con.Open();
    ArrayList al = new ArrayList();
    SqlDataReader sdr = cmd.ExecuteReader();
    while (sdr.Read())
    {
        object[] values = new object[sdr.FieldCount];
        sdr.GetValues(values);
        al.Add(values);
    }
            
   this.str = ((int[])al.ToArray(typeof(int)));
}





i我收到以下错误



At源数组中至少有一个元素无法转换为目标数组类型。



任何人都可以帮助我吗?



i am getting the following error

At least one element in the source array could not be cast down to the destination array type.

can any one pls help me ?

推荐答案

从错误中可以看出, ArrayList 包含的数据不是相同的 DataType



请调试并检查 ArrayList 中的所有值是否都是整数
From the error, it is clear that the ArrayList contains data which are not of the same DataType.

Please debug and check whether all the values in the ArrayList are Integer or not.


数组列表中的某些内容不能转换为整数,可能是空值或类似的东西。在this.str = ...行放一个断点,看看数组列表填充了什么,如果你看到任何看起来不像它可以强制转换为整数(null,奇数字符串等),那么这是你的问题。
Something in your array list can't be cast to an integer, probably a null value or something like that. Put a breakpoint at the this.str =... line and see what the array list is filled with, if you see anything that doesn't look like it can be cast to an integer (null, odd string, etc), then that's your problem.


请浏览链接 [ ^ ]。它有关于你的问题的详细解释。
Please go through the Link[^]. It has detailed explanation about your problem.


这篇关于源数组中至少有一个元素无法转换为目标数组类型。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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