linq to sql 查询出来的结果 转换成dataset datatable

 我来答
depluin
2012-07-01 · TA获得超过3179个赞
知道大有可为答主
回答量:3378
采纳率:75%
帮助的人:2478万
展开全部
最笨的办法返拿神:查询出结果后实例化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;
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式