真难啊,SqlDataAdapter 不更新数据库,也不提示错误!!
数据库不更新,也没有错误提示,怎么回事啊?向各位大虾求教了
代码说明如下:
private SqlCommand GetModNewsCom()
{
SqlCommand modNewCom = new SqlCommand( "update News set Title = @Title,Content = @Content,NewsPic = @NewsPic,[Date] =
@Date,Status = @Status,Degree = @Degree where NewsID = @NewsID ",new
SqlConnection( "server=127.0.0.1;uid=sa;pwd=123456;database=Data "));
modNewCom.CommandType = CommandType.Text;
SqlParameterCollection sqlParam = modNewCom.Parameters;
//添加参数
sqlParam.Add(new SqlParameter( "@NewsID ",SqlDbType.Int));
sqlParam.Add(new SqlParameter( "@Title ",SqlDbType.NVarChar,100));
sqlParam.Add(new SqlParameter( "@Content ",SqlDbType.NText));
sqlParam.Add(new SqlParameter( "@NewsPic ",SqlDbType.NVarChar,100));
sqlParam.Add(new SqlParameter( "@Date ",SqlDbType.SmallDateTime));
sqlParam.Add(new SqlParameter( "@Status ",SqlDbType.TinyInt));
sqlParam.Add(new SqlParameter( "@Degree ",SqlDbType.Int));
//设置参数映射
sqlParam[ "@NewsID "].SourceColumn = "NewsID ";
sqlParam[ "@Title "].SourceColumn = "Title ";
sqlParam[ "@Content "].SourceColumn = "Content ";
sqlParam[ "@NewsPic "].SourceColumn = "NewsPic ";
sqlParam[ "@Date "].SourceColumn = "[Date] ";
sqlParam[ "@Status "].SourceColumn = "Status ";
sqlParam[ "@Degree "].SourceColumn = "Degree ";
return modNewCom;
}
public bool ModNews(DataSet news)
{
SqlDataAdapter da=new SqlDataAdapter();
da.TableMappings.Add( "table ", "News ");
if(da==null)
{
throw new System.ObjectDisposedException( GetType().FullName );
}
da.UpdateCommand=GetModNewsCom();
if(da.Update(news, "News ")==0)
{ return false;}//运行结果是没有更新记录
else
{return true;}
//DataRow row = news.Tables[ "News "].Rows[0];
//string title0= row[ "Title "].ToString();
//string content0 = row[ "Content "].ToString();
//Int32 id0 = Convert.ToInt32(row[ "NewsID "]);
//这几行注释是用来测试的,运行时,都有要更新的新内容
}
------解决方案--------------------程序运行没错误? 帮你顶下
------解决方案--------------------用Profiler跟踪sql看看
*****************************************************************************
欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码)
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
------解决方案--------------------你不是看看没有更新记录
DataSet的HasChanges
da.Update()只调用相应的SQL语句
需要ExecuteNonQuery();
------解决方案--------------------学习