日期:2014-05-18  浏览次数:20415 次

微软 .xsd(数据集)自动生成的代码 问题
public virtual searchDataSet.hg_searchDataTable GetsearchByCondition(string Condition, string SortExpression) {
  this.Adapter.SelectCommand = this.CommandCollection[2];
  if ((Condition == null)) {
  this.Adapter.SelectCommand.Parameters[1].Value = global::System.DBNull.Value;
  }
  else {
  this.Adapter.SelectCommand.Parameters[1].Value = ((string)(Condition));
  }
  if ((SortExpression == null)) {
  this.Adapter.SelectCommand.Parameters[2].Value = global::System.DBNull.Value;
  }
  else {
  this.Adapter.SelectCommand.Parameters[2].Value = ((string)(SortExpression));
  }
  searchDataSet.hg_searchDataTable dataTable = new searchDataSet.hg_searchDataTable();
  this.Adapter.Fill(dataTable);
  return dataTable;
  }

上面一段是我从.xsd中copy一段出来的。不过看上面好像没有用try ..catch ...finally。。有没有人用过用数据集直接生成代码这种做法??

------解决方案--------------------
生成的代码类似于库。一般情况下,库不处理异常。异常应该由调用库的代码处理。
------解决方案--------------------
xsd数据集不处理异常,只能自己处理!!
还有xsd数据集是自动生成的,
完全没必要拷贝这个代码来用!!
好象也没看到这样的用法!!
------解决方案--------------------
楼上的解释很清楚了

xsd就是没有try catch

需要你自己写 至于写在哪 看你自己的控制
------解决方案--------------------
xsd文件是所见即所得的对表的访问!
1.你实例化其中的类就可访问其中的方法了!
2.也可通过ObjectDataSource控件直接对xsd文件中的类访问!!
3.try catch一搬编写在中间层!也就是在中间层实例化xsd其中的类!!