Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Search dataset for existing row

Posted on 2010-01-11
5
Medium Priority
?
480 Views
Last Modified: 2013-11-08
I have a dataset that I am binding a Gridview on a Webform.   I need to search thru the dataset and see if a specific row exists based on a value in a column.   If the specific row does not exist i need to add it.  If it does already exist i dont need to do anything.  

How can I do this?
0
Comment
Question by:Mike_Stevens
  • 3
5 Comments
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 26284000
If the value you are using to search with is a primary key value in the table then use:
datatable1.find()

if the value is not a primary key use:
datatable1.select()
0
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 26284091
0
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 26284187
This may be a little clearer:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23640122.html

Let me know if this is detailed enough.
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 26284476
Dim drRow() As Datarow

drRow = ds.Tables(0).Select("ColumnName = '" + ColumnValue + "'")

If Not drRow.Length >0 Then

Add Row

End IF
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 26303545
How about this

dTable.DefaultView.RowFilter = "columnname = '" & value & "'"

or

dTable.DefaultView.RowFilter = "columnname like '%" & value & "%'"

then

If dTable.DefaultView.Count >0 then
   'row already exists
Else
   'row does not exist
End If
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question