how yo trap this second column?
i want to trap, example i have foreign key or itemno 1 with rose if i attemp to add rose under itemno 1 it will trap me
Code:
If TxtItemNu.Text = "" Then
MsgBox "No Item Number entered.", vbOKOnly + vbCritical, "ERROR: Empty field/s. "
' TxtItemNu.SetFocus
Exit Sub
End If
If TxtFlowerID.Text = "" Then
MsgBox "No Flower ID entered.", vbOKOnly + vbCritical, "ERROR: Empty field/s. "
' TxtFlowerID.SetFocus
Exit Sub
End If
If CboQuantity.Text = "" Then
MsgBox "No Quantity entered.", vbOKOnly + vbCritical, "ERROR: Empty field/s. "
CboQuantity.SetFocus
Exit Sub
End If
On Error GoTo errSave
Dim sqlstr As String
sqlstr = "Insert Into STRUCTURE(STR_ITEMNO,STR_FLOWER,STR_QTY) values(" & TxtItemNu.Text & "," & TxtFlowerID.Text & "," & CboQuantity.Text & ")"
If CStr(TxtItemNu.Text) = CStr(TxtFlowerID.Text) Then
MsgBox ("The Item Number Can't be The Same with Flower ID")
Exit Sub
End If
Conn.BeginTrans
Conn.Execute sqlstr
Conn.CommitTrans
MsgBox "STRUCTURE successfully saved!"
CmdSave.Enabled = False
CmdDelete.Enabled = False
ClearText
Unload Me
Form1.Show
ExitErr:
Exit Sub
errSave:
Conn.RollbackTrans
MsgBox "Error" & Err.Description, vbCritical
Resume ExitErr
End Sub
how can i do that?
to avoid redundancy itemname in every itemno...
Re: how yo trap this second column?
I cannot help you with VB6 but in sql server side you can do some things.
You can set a trigger to check for you if the value is the same and stop execution.
You can create an unique index that can be done easily with management studio.
Re: how yo trap this second column?
If you wish to do check for foreign key before inserts, you would be better off with a stored procedure.
A simple example is here.
Re: how yo trap this second column?
Ok a little spam here but abhijit what is this beside you on your avatar? :bigyello:
Re: how yo trap this second column?
Create relevant database constraints