|
-
Oct 4th, 2010, 02:04 PM
#1
Thread Starter
Member
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...
-
Oct 4th, 2010, 06:24 PM
#2
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.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Oct 4th, 2010, 07:12 PM
#3
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.
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Oct 4th, 2010, 07:37 PM
#4
Re: how yo trap this second column?
Ok a little spam here but abhijit what is this beside you on your avatar?
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Oct 4th, 2010, 10:52 PM
#5
Re: how yo trap this second column?
Create relevant database constraints
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|