ADDITION TO RECORDSET<ERRORS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vbbeginner07
    New Member
    • Dec 2007
    • 103

    ADDITION TO RECORDSET<ERRORS

    [code=vb]
    Private Sub cmdAdd_Click()
    txtid.Enabled = True
    If txtid.Text = " " Then
    MsgBox "Enter the id,Please!!!", vbOKOnly, "PAYROLL"
    txtid.SetFocus
    With txtid
    .SelStart = 0
    '.SelLength = Len(txtid.Text)
    .SetFocus
    End With
    Exit Sub
    ElseIf txtname.Text = " " Then
    MsgBox "Enter the name,Please!!!" , vbOKOnly, "PAYROLL"
    'txtname.SetFoc us
    Exit Sub

    With txtname
    .SelStart = 0
    ' .SelLength = Len(txtname.Tex t)
    .SetFocus

    End With
    'End If
    ElseIf txtwhr.Text = " " Then
    MsgBox "Enter the working hours,Please!!! ", vbOKOnly, "PAYROLL"
    txtwhr.SetFocus
    Exit Sub
    With txtwhr
    .SelStart = 0
    '.SelLength = Len(txtwhr.Text )
    .SetFocus
    End With
    ElseIf Form1.txtrate.T ext = " " Then
    MsgBox "Enter the rate,Please!!!" , vbOKOnly, "PAYROLL"
    txtrate.SetFocu s
    Exit Sub
    With txtrate
    .SelStart = 0
    .SetFocus
    End With
    ElseIf txtorate.Text = " " Then
    MsgBox "Enter the Overtime Rate,Please!!!" , vbOKOnly, "PAYROLL"
    txtorate.SetFoc us
    Exit Sub
    With txtorate
    .SelStart = 0
    .SetFocus
    End With
    Else
    rs.Open "select * from empdetail Where ID='" & txtid.Text & "'", conn, adOpenStatic, adLockOptimisti c
    If rs.EOF Then
    conn.Execute "insert into empdetail(id,na me,whours,rate, otrate) values ('" & txtid & "','" & txtname & "','" & txtwhr & "','" & txtrate & "','" & txtorate & "')"
    MsgBox "INSERTED NEW RECORDS", vbOKOnly, "ADDING NEW RECORDS"
    Else

    MsgBox "Duplicate Entry"
    End If

    rs.Close
    Set rs = Nothing
    ListView1.ListI tems.Clear
    addcol
    Form1.txtid.Tex t = ""
    Form1.txtname.T ext = ""
    Form1.txtwhr.Te xt = ""
    Form1.txtrate.T ext = ""
    Form1.txtorate. Text = ""
    End If

    End Sub
    Private Sub cmdBack_Click()
    Form1.txtid.Tex t = ""
    Form1.txtname.T ext = ""
    Form1.txtwhr.Te xt = ""
    Form1.txtrate.T ext = ""
    Form1.txtorate. Text = ""
    Form1.Hide
    MDIForm1.Show
    End Sub[/code]


    This above code is for adding four fields to databse where id the primary kiey.Please go through because,its works for once,ie when one data gets inserted,u dont have any pblm.But whenthe computation is done for the second time without closing the window,an error occurs!!!
    Please Go through........ ...!!!!!~
    Where I HAve go wrong????
    Last edited by debasisdas; Jan 11 '08, 06:48 AM. Reason: Formatted using code tags.
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by Vbbeginner07
    code:vb

    This above code is for adding four fields to databse where id the primary kiey.Please go through because,its works for once,ie when one data gets inserted,u dont have any pblm.But whenthe computation is done for the second time without closing the window,an error occurs!!!
    Please Go through........ ...!!!!!~
    Where I HAve go wrong????
    Hello, Vbbeginner07!

    What are you hoping the above code does?

    I am just trying to get a handle on what you are asking for. Can you go into it a little more?

    Dököll
    Last edited by Dököll; Jan 11 '08, 04:54 AM. Reason: removed [CODE=VB], and code...

    Comment

    • Vbbeginner07
      New Member
      • Dec 2007
      • 103

      #3
      Originally posted by Dököll
      Hello, Vbbeginner07!
      What are you hoping the above code does?
      I am just trying to get a handle on what you are asking for. Can you go into it a little more?
      Dököll
      Hi DoKoll,
      the above code is for ADD ing datas to a database,the form actually contains five fileds
      id ,which is the primary key
      name(of employee)
      working hours(emp)
      rate(per hours)
      overtime rate(if he does,per hours)
      The code works for the very first time,ie when one data gets inserted into the database,if we click ADD button(command button)it gives errors,where i have given specific constraints for each field,why is it so...???
      Where i have gone wrong???
      Ant More explanation???

      Nick

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        please try to use this

        [code=vb]
        conn.BeginTrans
        conn.Execute "insert into empdetail(id,na me,whours,rate, otrate) values ('" & txtid & "','" & txtname & "','" & txtwhr & "','" & txtrate & "','" & txtorate & "')"
        conn.commmittra ns
        [/code]

        that might help you.

        Comment

        Working...