C# 无法强制转换类型为';System.Data.DataRow';输入';System.IConvertible';。不能';t商店<;System.Data.DataRow>;在regid列中

C# 无法强制转换类型为';System.Data.DataRow';输入';System.IConvertible';。不能';t商店<;System.Data.DataRow>;在regid列中,c#,asp.net,C#,Asp.net,我一直在使用for循环将数据集值添加到datatable中。请查看代码并帮助我。它抛出的错误与预期的int32相同 string allCtries = string.Empty; allCtries = com.COUNTRY_ID; string[] splitctrs = new string[] { }; splitctrs = allCtries.Split(','); string m_Query = string.Empty; DataSet dsPck = new DataSet

我一直在使用for循环将数据集值添加到datatable中。请查看代码并帮助我。它抛出的错误与预期的int32相同

string allCtries = string.Empty;
allCtries = com.COUNTRY_ID;
string[] splitctrs = new string[] { };
splitctrs = allCtries.Split(',');
string m_Query = string.Empty;
DataSet dsPck = new DataSet();
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("regid", typeof(int)),
                                                    new DataColumn("cid", typeof(int)),
                                                    new DataColumn("pid", typeof(int)) });
foreach (string val in splitctrs)
{
    dsPck = con.GetDataSet("select  registrationid, country_id, product_id from registration where product_id = " + com.PRODUCT_ID + " and country_id = " + val + "", CommandType.Text, ConnectionState.Open);
    DataRowCollection drr = dsPck.Tables[0].Rows;
    foreach (var row in drr)
        dt.Rows.Add(row);
    //if (dsPck.Tables[0].Rows.Count> 0)
    //{
    //    dt.Rows.Add(dsPck);
    //}
}
用这个

foreach (DataRow dr in dsPck.Tables[0].Rows) 
{
    dt.Rows.Add(dr.ItemArray);
}
反而

DataRowCollection drr = dsPck.Tables[0].Rows;
                foreach (var row in drr)
                    dt.Rows.Add(row);

你已经试过用Int32代替int了吗?是的。我试过Int32,int64,但也会抛出错误。在这里抛出错误dt.Rows.Add(row);检查数据库表“Registration”中的所有字段是否为int且不为NULL