Solved

Check If Record Is New Data

Posted on 2004-10-14
9
224 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
Independent Software Vendors: 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 125 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

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!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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