?
Solved

Search dataset for existing row

Posted on 2010-01-11
5
Medium Priority
?
471 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 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