?
Solved

Check If Record Is New Data

Posted on 2004-10-14
9
Medium Priority
?
231 Views
Last Modified: 2011-09-20
How do I check to see if new data entered into a bound textbox already exists in the table?
If it doesn’t then I need to fill some fields
However if it already exists I need to check if the text in another textbox matches a field an the current record, if it does then I need to fill some different fields

Thanks
0
Comment
Question by:daverichardson
[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
  • 5
  • 4
9 Comments
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12310960
If DS.Tables("MyTable").Rows.Contains(me.textbox1.text) Then
    'Dont save
Else
    'Save
End If
0
 

Author Comment

by:daverichardson
ID: 12310995
i get an error
Input string was not in a correct format
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12311044
CHek the datatype. If you are looking for number do the cast.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:daverichardson
ID: 12311092
there are various columns in the table with various datatypes, but its only one column i need to search

Dave
0
 

Author Comment

by:daverichardson
ID: 12311098
can i specify the comumn?
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12311264
This code works for the primary key column. I f you want to check if this value exist the col must be primary key.
If it is not a case you have to create datareader for thsi column and then and loop through it
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12311307
Another approach would be to create unique field for this column and then put try catch block when you saving a record.
Let me know if you need help wiht unique field
0
 

Author Comment

by:daverichardson
ID: 12311321
could you point me in the right dirrection on how to do this
0
 
LVL 28

Accepted Solution

by:
iboutchkine earned 500 total points
ID: 12311469
Here is an example how to create datatable with unique filelds

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region

    Private m_DataSet As DataSet
    Private m_dtPeople As DataTable

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Build the DataSet.
        m_DataSet = New DataSet()

        ' Build the People table.
        m_dtPeople = New DataTable("People")
        m_DataSet.Tables.Add(m_dtPeople)
        m_dtPeople.Columns.Add("LastName", GetType(String))
        m_dtPeople.Columns.Add("FirstName", GetType(String))
        m_dtPeople.Columns.Add("Notes", GetType(String))

        ' Make the UniqueConstraint on LastName
        ' and FirstName.
        Dim data_columns(1) As DataColumn
        Dim unique_constraint As UniqueConstraint

        data_columns(0) = m_dtPeople.Columns("LastName")
        data_columns(1) = m_dtPeople.Columns("FirstName")
        unique_constraint = New UniqueConstraint(data_columns)
        m_dtPeople.Constraints.Add(unique_constraint)

        ' Populate the People table.
        Dim people_data(2) As String
        people_data(0) = "Abercrombe"
        people_data(1) = "Alice"
        people_data(2) = ""
        m_dtPeople.Rows.Add(people_data)

        people_data(0) = "Bouf"
        people_data(1) = "Brian"
        people_data(2) = "Brian@nowhere.com"
        m_dtPeople.Rows.Add(people_data)

        people_data(0) = "Carnivale"
        people_data(1) = "Cynthia"
        people_data(2) = "Phone: 987-654-3210"
        m_dtPeople.Rows.Add(people_data)

        ' Attach the DataGrid to the DataTable.
        dgPeople.DataSource = m_dtPeople
    End Sub
End Class



Now if you try to add duplicate field you will get an exception. Put your save record to the try-catch block and catch this exception
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

771 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