Filter records from the dataset in vb.net

vps picture vps · Sep 14, 2012 · Viewed 19.1k times · Source

I want to filter values from a dataset. It contain phone numbers starting with zero and non zero values. How can I filter a phone number (start with non zero no) from the dataset. Below is the vb.net code and the resulting error.

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'"

Error: Object reference not set to an instance of an object. error in rowfilter line

Answer

Pilgerstorfer Franz picture Pilgerstorfer Franz · Sep 14, 2012

Within your ds1 there is no table *reports.renewal_contact_t*. Change it to

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'"