日期:2014-05-17  浏览次数:20426 次

用SqlBulkCopy批量插入数据时提示来自数据源的 String 类型的给定值不能转换为指定目标列的类型 int。
DataTable dt = new DataTable();
            dt.Columns.Add("greouparea", typeof(System.Int32));
            dt.Columns.Add("grouptype", typeof(System.Int32));
            dt.Columns.Add("name", typeof(System.String));
            dt.Columns.Add("mainperson", typeof(System.String));
            dt.Columns.Add("groupform", typeof(System.String));
            dt.Columns.Add("scale", typeof(System.String));
            dt.Columns.Add("nature", typeof(System.Int32));
            dt.Columns.Add("description", typeof(System.String));
            dt.Columns.Add("level", typeof(System.Int32));
            dt.Columns.Add("groupuser", typeof(System.String));
            dt.Columns.Add("reportedsource", typeof(System.Int32));
            dt.Columns.Add("localid", typeof(System.Int32));
            dt.Columns.Add("userid", typeof(System.Int32));
            dt.Columns.Add("remark", typeof(System.String));
            DataRow dr = dt.NewRow();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dr = dt.NewRow();
                dr["name"] = ds.Tables[0].Rows[i]["组织名称"].ToString();
                dr["nature"] = param.id;
                dr["reportedsource"] = local.id;
                dr["localid"] = local.id;
                dr["level"] = Model.id;
                dr["scale"] = ds.Tables[0].Rows[i]["组织规模"].ToString();
                dr["greouparea"] = ds.Tables[0].Rows[i]["组织地域"].ToString() == "境内组织" ? 10 : 11;
                dr["grouptype"] = ds.Tables[0].Rows[i]["组织类型"].ToString() == "网络组织 " ? 0 : 1;
                dr["mainperson"] = ds.Tables[0].Rows[i]["