Table validating

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey all,

If I need to just validate a single record against a table to see if it
exist, what's the best /fastest method to do this? shoud I create a table in
my dataset for such a task? this is an asp.net.vb app.


thanks,
rodchar
 
Hi Rod,

I generally create a dataset/datatable and make a view of it, sort it on the
pk you're row provides; then use the find method. If it returns anything
except -1, it found the row. Sounds longer than you think - takes
miliseconds to execute.

HTH,

Bernie Yaeger
 
i appreciate it.

Bernie Yaeger said:
Hi Rod,

I generally create a dataset/datatable and make a view of it, sort it on the
pk you're row provides; then use the find method. If it returns anything
except -1, it found the row. Sounds longer than you think - takes
miliseconds to execute.

HTH,

Bernie Yaeger
 
rodchar,
In addition to Bernie's suggestion.

How big a table are you checking against?

If the table is not too large, I would create a DataTable out of it, define
a primary key, then use the Contains method.

Something like:

' define the table, only really need the primary keys
Dim table As New DataTable
table.Columns.Add("id", GetType(Integer))
table.PrimaryKey = New DataColumn() {table.Columns("id")}


' check to see if the row is in the table.
Dim key As Integer
If table.Rows.Contains(key) Then

End If

If you want to check the entire record, I would define all the fields as
keys. Contains is overloaded to accept a single value as above or an array
of values...

If the table is too large, I would use SQL do have the database itself check
for the record (with a SELECT statement or a Unique constraint).

Hope this helps
Jay
 
Rodchar,

In addition to Jay, I would just go for his last suggestion and than read
it with an SQLCommand.executenonscalar using a where statement in the SQL
string.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top