4

我想从数据集中过滤值它包含以零和非零值开头的电话号码。如何从数据集中过滤电话号码(以非零开头)。下面是 vb.net 代码和产生的错误。

cmd = New OracleCommand("select  PHONE from  reports.renewal_contact_t where run_date=to_date('" + TextBox1.Text + "','mm/dd/yyyy') and  EXP_DATE =to_date('" + TextBox2.Text + "','mm/dd/yyyy') and  region not in('TNP')", cn)
ada = New OracleDataAdapter(cmd)
ada.Fill(ds, "reports.renewal_contact_t ")
Dim ds1 As New DataSet
ds1.Tables("reports.renewal_contact_t").DefaultView.RowFilter = "PHONE NOT like'0'"

错误:对象引用未设置为对象的实例。行过滤器行中的错误

4

2 回答 2

3

在您的 ds1 中没有表*reports.renewal_contact_t*。将其更改为

cmd = New OracleCommand("select  PHONE from  reports.renewal_contact_t where run_date=to_date('" + TextBox1.Text + "','mm/dd/yyyy') and  EXP_DATE =to_date('" + TextBox2.Text + "','mm/dd/yyyy') and  region not in('TNP')", cn)
ada = New OracleDataAdapter(cmd)
ada.Fill(ds, "reports.renewal_contact_t")
' no need for a new dataset - as you fill ds (and not ds1)!!
ds.Tables("reports.renewal_contact_t").DefaultView.RowFilter = "PHONE NOT like'0'"
于 2012-09-14T06:27:58.257 回答
1

这将适用于具有类似于“模式”的数据集

**数据示例>*

Id   Value

1    303-888-8888
2    0-418-895-9598

TryCast(filteredDS.Tables(0).Rows.Cast(Of DataRow).Where(Function(row) Not row.ItemArray(1).ToString().Substring(0, 1).Equals("0")), IEnumerable(Of DataRow)).ToList().ForEach(Sub(row) row.Delete())

--删除电话以非零开头的任何记录

于 2013-03-14T19:08:34.763 回答