Results 1 to 5 of 5

Thread: how yo trap this second column?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2010
    Posts
    53

    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...

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    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.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    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

  4. #4
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: how yo trap this second column?

    Ok a little spam here but abhijit what is this beside you on your avatar?
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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
  •  



Click Here to Expand Forum to Full Width