Please Check the code

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

    Please Check the code

    THE FOLLOWING CODE INSERTS A PARTICULAR DATA INTO THE recordset WHICH IS THE FIRST FORM!!!
    [code=vb]
    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
    [/code]
    THE SECONF FORM CONTAINS A LISTVIEW ,WHICH HAS TO DISPLAY THE RECORDS saved through FORM 1
    [code=vb]
    rs.Open "select distinct empdetail.name, saldetail1.id from empdetail,salde tail1 where saldetail1.id = empdetail.id", conn, adOpenStatic, adLockOptimisti c
    If Not rs.EOF Then
    rs.MoveFirst
    Do While Not rs.EOF
    With ListView1
    Set lvitem = ListView1.ListI tems.Add(, , rs!id)
    lvitem.SubItems (1) = rs!Name
    rs.MoveNext
    End With
    Loop
    End If
    rs.Close
    Set rs = Nothing
    ListView1.Refre sh
    ListView2.Refre sh
    [/code]
    BUT THAT IS NOT WORKING!~!!!,
    the code displays only the first inserted record in ht listview,but htt nexrt added records is not dispalying
    PLEASE SUGGEST<THNAKS IN ADVANCE!!!
    Last edited by debasisdas; Feb 13 '08, 08:50 AM. Reason: added code=vb tags
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    try using this

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

    Comment

    • Vbbeginner07
      New Member
      • Dec 2007
      • 103

      #3
      Originally posted by debasisdas
      try using this

      [code=vb]
      conn.begintrans
      conn.Execute "insert into empdetail(id,na me,whours,rate, otrate) values ('" & txtid & "','" & txtname & "','" & txtwhr & "','" & txtrate & "','" & txtorate & "')"
      conn.commitrans
      [/code]
      Debasis not working........ .
      Please go through my code n please suggest......
      Nick

      Comment

      • Vbbeginner07
        New Member
        • Dec 2007
        • 103

        #4
        Originally posted by Vbbeginner07
        Debasis,its not working........ .
        Please go through my code n please suggest......
        Nick
        Debasis,its not working........ .
        Please go through my code n please suggest......
        it allows only the first records being added,if we checks form2 that will be displayed,but if we add any records second time it is not displayed

        Comment

        • debasisdas
          Recognized Expert Expert
          • Dec 2006
          • 8119

          #5
          If both of your forms are opened at the same time you need to fresh the recordset in form2 after adding the recods in form1.

          Comment

          • Vbbeginner07
            New Member
            • Dec 2007
            • 103

            #6
            Originally posted by debasisdas
            If both of your forms are opened at the same time you need to fresh the recordset in form2 after adding the recods in form1.
            not two recordsets are opened at the sametime,n tell me how a sql recoredset be refreshed???tel l me the code to refersh
            NICK

            Comment

            • mafaisal
              New Member
              • Sep 2007
              • 142

              #7
              Hello
              try this
              Code:
              if Rs.state =1 then rs.close
              Originally posted by Vbbeginner07
              not two recordsets are opened at the sametime,n tell me how a sql recoredset be refreshed???tel l me the code to refersh
              NICK

              Comment

              • debasisdas
                Recognized Expert Expert
                • Dec 2006
                • 8119

                #8
                try to use this

                [code=vb]
                rs.Requery
                [/code]

                Comment

                • QVeen72
                  Recognized Expert Top Contributor
                  • Oct 2006
                  • 1445

                  #9
                  Hi,

                  After looking at your Code, I feel that, You Query for EmpID, If No Record is found, then You add /Insert One Record. So at any given time, Only one Related EmpID is there in the Detail Table. So the ListView Shows only one Record.. Any kind of Re-Freshing the RecordSet will fetch you only One Record.
                  You can Cross-Check by Actual Querying the data in the Table


                  Regards
                  Veena

                  Comment

                  • Vbbeginner07
                    New Member
                    • Dec 2007
                    • 103

                    #10
                    Originally posted by debasisdas
                    try to use this

                    [code=vb]
                    rs.Requery
                    [/code]
                    rs.requery is not working i have tried this,but i dont think there's a option for refreshing in sql...if any please suggest
                    NICK

                    Comment

                    • Vbbeginner07
                      New Member
                      • Dec 2007
                      • 103

                      #11
                      Originally posted by QVeen72
                      Hi,
                      After looking at your Code, I feel that, You Query for EmpID, If No Record is found, then You add /Insert One Record. So at any given time, Only one Related EmpID is there in the Detail Table. So the ListView Shows only one Record.. Any kind of Re-Freshing the RecordSet will fetch you only One Record.
                      You can Cross-Check by Actual Querying the data in the Table
                      Regards
                      Veena
                      Veena,i couldnt understand,what u have pointed out and the method suggested"
                      You can Cross-Check by Actual Querying the data in the Table "
                      Please explain and the code for adding records are:
                      [code=vb]
                      rs.Open "select * from empdetail Where ID='" & txtid.Text & "'", conn, adOpenStatic, adLockOptimisti c
                      If rs.EOF Then
                      conn.BeginTrans
                      conn.Execute "insert into empdetail(id,na me,whours,rate, otrate) values ('" & txtid & "','" & txtname & "','" & txtwhr & "','" & txtrate & "','" & txtorate & "')"
                      conn.CommitTran s
                      MsgBox "INSERTED NEW RECORDS", vbOKOnly, "ADDING NEW RECORDS"
                      Else
                      'ID Found In DB (Duplicate)
                      MsgBox "Duplicate Entry"
                      End If
                      [/code]
                      Nick
                      Last edited by debasisdas; Feb 14 '08, 11:45 AM. Reason: added code=vb tags

                      Comment

                      • QVeen72
                        Recognized Expert Top Contributor
                        • Oct 2006
                        • 1445

                        #12
                        Hi,

                        If you are using Access, Open the Access, and Find how many records are thre in EmpDetail and SalDetail Tables, and ow many of them Match (having same EmpID)

                        Regards
                        Veena

                        Comment

                        • Vbbeginner07
                          New Member
                          • Dec 2007
                          • 103

                          #13
                          Originally posted by QVeen72
                          Hi,
                          if you are using Access, Open the Access, and Find how many records are thre in EmpDetail and SalDetail Tables, and ow many of them Match (having same EmpID)
                          Regards
                          Veena
                          Ok,but im using sql server...the same can be done here too???

                          NICK

                          Comment

                          • QVeen72
                            Recognized Expert Top Contributor
                            • Oct 2006
                            • 1445

                            #14
                            Hi,

                            If you are using SQL Server, Query the table Data in ISQL/W Or Enterprise Manager's Query Tool..

                            REgards
                            Veena

                            Comment

                            Working...