how to have Insert or Select Statement NOT allow Duplicates

R

rickn

Being new to VB and programming, I'm not sure how to modify the
following or if required have a Select statement to NOT allow any
duplicates. I'm trying not to have any duplicates in the LOTNUM_72
field. The data is coming from odbc and being inserted via ole into
access. IF the LOTNUM_72 field is set as Prinary Key, then no records
are inserted if any duplicates are seen.

I'n not sure at all how to make the coding so if a duplicate does exist
it is not entered and the remaining data is.

icount = 0 'set the value to count the number of tickets
DataSet1.AcceptChanges()
For Each rowX As DataRow In DataSet1.Lot_Tracking_Hist.Rows
sSQL = "INSERT INTO [LotTrackingHistory] (LOTNUM_72,
TNXDTE_72, PRTNUM_72, USRNAM_72," & _
"STKID_72,
TNXQTY_72, ORDNUM_72, UDFREF_72)" & _
" Values " & _
"('" & rowX.Item("LOTNUM_72").ToString & "'," & _
"#" & rowX.Item("TNXDTE_72") & "#," & _
"'" & rowX.Item("PRTNUM_72").ToString & "'," & _
"'" & rowX.Item("USRNAM_72").ToString & "'," & _
"'" & rowX.Item("STKID_72").ToString & "'," & _
"'" & rowX.Item("TNXQTY_72").ToString & "'," & _
"'" & rowX.Item("ORDNUM_72").ToString & "'," & _
"'" & rowX.Item("UDFREF_72").ToString & "')"

With objCommand ' this portion identifies the
connection that will supply the data to be entered duing the commands
.Connection = oOleDbConnection
.CommandText = sSQL
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
'Count the number of entries and display them. Lets
create a message box and display the results of data entered
icount += 1 'total number of tickets processed

Next
MessageBox.Show(icount, "Total Number Tickets Entered In
Lab Table") 'Total Tickets Entered in Lab Table
' If icount > 1 Then MessageBox.Show(icount, "No Tickets
Entered")
oOleDbConnection.Close() ' data is completed and time to
close the ole connection
oOleDbConnection = Nothing
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
 
H

Homer J Simpson

Being new to VB and programming, I'm not sure how to modify the
following or if required have a Select statement to NOT allow any
duplicates. I'm trying not to have any duplicates in the LOTNUM_72
field. The data is coming from odbc and being inserted via ole into
access. IF the LOTNUM_72 field is set as Prinary Key, then no records
are inserted if any duplicates are seen.

Set LOTNUM_72 as a key: must be unique / no duplicates allowed. It need not
be primary.
 

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

Similar Threads


Top