DateSet如何改变表格中的值?

baryjim 2005-10-22 02:34:08
string Select = @"SELECT * FROM clubmember where (Enroll=1)"+where;

SqlDataAdapter adapter = new SqlDataAdapter(Select ,objConnection);

DataSet ds = new DataSet();
adapter.Fill(ds,"InferEngineInfo");

foreach(DataRow dr in ds.Tables["InferEngineInfo"].Rows)
{
dr["birthday"]="1980-11-21";
}

请问为什么不起作用??dr["birthday"]的值还是原先的
...全文
76 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
baryjim 2005-10-22
  • 打赏
  • 举报
回复
我不是已经用了dt.ToShortDateString()了吗
tclin 2005-10-22
  • 打赏
  • 举报
回复
对字符串进行DateTime.Parse()转换后才可能给dr["birthday"]赋值的。因为字符串跟DataTime跟String之间没有隐式转换。记住先得去查一下转换的时候应该用哪个参数才跟那种字符串相付合
baryjim 2005-10-22
  • 打赏
  • 举报
回复
用Datagrid输出
axqd 2005-10-22
  • 打赏
  • 举报
回复
那当然就要看你怎么输出拉:)
baryjim 2005-10-22
  • 打赏
  • 举报
回复
DataSet ds = new DataSet();
adapter.Fill(ds,"InferEngineInfo");

for(int i=0;i<ds.Tables["InferEngineInfo"].Rows.Count;i++)
{
DateTime dt=DateTime.Parse(ds.Tables["InferEngineInfo"].Rows[i]["birthday"].ToString());
ds.Tables["InferEngineInfo"].Rows[i]["birthday"] = dt.ToShortDateString();
}

我都这样做了,断点调试的时候已经表明结果是“1980-11-29”形式,为什么输出还是
1980-11-29 00:00:00
CSDNATM 2005-10-22
  • 打赏
  • 举报
回复
ds.Tanle["InferEngineInfo"].Rows[i]["birthday"] = "1980-11-21";

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧