linq to sql 查询出来的结果 转换成dataset datatable
展开全部
最笨的办法返拿神:查询出结果后实例化dataset跟datatable然后把数敏轮据复制过去
dt.Columns.Add("UserID", typeof (long));
dt.Columns.Add("UserName", typeof (string));
dt.Columns.Add("UserQuestion", typeof (string));
dt.Columns.Add("UserAnswer", typeof (string));
dt.Columns.Add("UserEmail", typeof (string));
dt.Columns.Add("TrueName", typeof (string));
dt.Columns.Add("UserSex", typeof (string));
dt.Columns.Add("UserBirthday", typeof (string));
dt.Columns.Add("IDCardNumber", typeof (string));
dt.Columns.Add("ProvinceID", typeof (long));
dt.Columns.Add("CityID", typeof (long));
dt.Columns.Add("DistrictID", typeof (long));
dt.Columns.Add("ZipCode", typeof (string));
dt.Columns.Add("LastLoginIP", typeof (string));
dt.Columns.Add("DateUpdated", typeof (DateTime));
dt.Columns.Add("DateCreated", typeof (DateTime));
DataRow dr = null;
ds.Tables.Add(dt);
IEnumerable<U_User_GetUserInfoByIDResult> userInfo = null;
try
{
userInfo = UserOption.U_User_GetUserInfoByID(userID);
foreach (U_User_GetUserInfoByIDResult info in userInfo)
{
dr = dt.NewRow();
dr["UserID"] = info.UserID;
dr["UserName"] = info.UserName;
dr["UserQuestion"] = info.UserQuestion;
dr["UserAnswer"] = info.UserAnswer;
dr["UserEmail"] = info.UserEmail;
dr["TrueName"] = info.TrueName;
dr["UserSex"漏亏] = info.UserSex;
dr["UserBirthday"] = info.UserBirthday;
dr["IDCardNumber"] = info.IDCardNumber;
dr["ProvinceID"] = Convert.ToInt64(info.ProvinceID);
dr["CityID"] = Convert.ToInt64(info.CityID);
dr["DistrictID"] = Convert.ToInt64(info.DistrictID);
dr["ZipCode"] = info.ZipCode;
dr["LastLoginIP"] = info.LastLoginIP;
dr["DateUpdated"] = Convert.ToDateTime(info.DateUpdated);
dr["DateCreated"] = Convert.ToDateTime(info.DateCreated);
ds.Tables[0].Rows.Add(dr);
}
}
catch (Exception ex)
{
throw ex;
}
return ds;
dt.Columns.Add("UserID", typeof (long));
dt.Columns.Add("UserName", typeof (string));
dt.Columns.Add("UserQuestion", typeof (string));
dt.Columns.Add("UserAnswer", typeof (string));
dt.Columns.Add("UserEmail", typeof (string));
dt.Columns.Add("TrueName", typeof (string));
dt.Columns.Add("UserSex", typeof (string));
dt.Columns.Add("UserBirthday", typeof (string));
dt.Columns.Add("IDCardNumber", typeof (string));
dt.Columns.Add("ProvinceID", typeof (long));
dt.Columns.Add("CityID", typeof (long));
dt.Columns.Add("DistrictID", typeof (long));
dt.Columns.Add("ZipCode", typeof (string));
dt.Columns.Add("LastLoginIP", typeof (string));
dt.Columns.Add("DateUpdated", typeof (DateTime));
dt.Columns.Add("DateCreated", typeof (DateTime));
DataRow dr = null;
ds.Tables.Add(dt);
IEnumerable<U_User_GetUserInfoByIDResult> userInfo = null;
try
{
userInfo = UserOption.U_User_GetUserInfoByID(userID);
foreach (U_User_GetUserInfoByIDResult info in userInfo)
{
dr = dt.NewRow();
dr["UserID"] = info.UserID;
dr["UserName"] = info.UserName;
dr["UserQuestion"] = info.UserQuestion;
dr["UserAnswer"] = info.UserAnswer;
dr["UserEmail"] = info.UserEmail;
dr["TrueName"] = info.TrueName;
dr["UserSex"漏亏] = info.UserSex;
dr["UserBirthday"] = info.UserBirthday;
dr["IDCardNumber"] = info.IDCardNumber;
dr["ProvinceID"] = Convert.ToInt64(info.ProvinceID);
dr["CityID"] = Convert.ToInt64(info.CityID);
dr["DistrictID"] = Convert.ToInt64(info.DistrictID);
dr["ZipCode"] = info.ZipCode;
dr["LastLoginIP"] = info.LastLoginIP;
dr["DateUpdated"] = Convert.ToDateTime(info.DateUpdated);
dr["DateCreated"] = Convert.ToDateTime(info.DateCreated);
ds.Tables[0].Rows.Add(dr);
}
}
catch (Exception ex)
{
throw ex;
}
return ds;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |