CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2006
    Posts
    65

    No. of row effected in Update/Insert Query

    Hi again,

    Dear all, I am again in trouble with my project of billing solution.
    In my project I have used some update and insert queries which modifies the raw data to calculate some billing effects. I want to show the number of rows effected on each update or insert query.

    e.g. If I use insert query, it will insert the data into table (lets say 5 records). after completion of insert query i want to display the "5" in label1.caption

    Short solution will be highly appreciated.

    Umar

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: No. of row effected in Update/Insert Query

    Post your code so we can see where the problem *might* be
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Nov 2004
    Location
    LA. California Raiders #1 AKA: Gangsta Yoda™
    Posts
    616

    Re: No. of row effected in Update/Insert Query

    Use an ADO connection object to .Execute the sql statement against your database. The second argument is the number or records affected.

    Code:
    Dim oCnn As ADODB.Connection
    Dim lRecs As Long
    
    Set oCnn = New ADODB.Connection
    oCnn.Connectionstring"Your connectionstring to your database etc"
    oCnn.Open
    
    'Then execute your insert sql
    oCnn.Execute "INSERT INTO Table1 VALUES('Test', 'Test2', Test3')", lRecs
    label1.caption = lRecs & " Record(s) added to the database."
    VB/Office Guru™ (AKA: Gangsta Yoda™)
    VB Forums - Super Moderator 2001-Present

    Microsoft MVP 2006-2011

    Please use [code]your code goes in here[/code] tags when posting code.

    Senior Software Engineer MCP, BSEE, CET
    VS 2012 Premium, VS 6.0 Enterprise SP6, VSTO, Office Ultimate 2010, Windows 7 Ultimate
    Star Wars Gangsta Rap SE Reputations & Rating Posts Office Primary Interop AssembliesAdvanced VB/Office Guru™ Word SpellChecker™.NETAdvanced VB/Office Guru™ Word SpellChecker™ VB6Outlook Global Address ListVB6/Crystal Report Ex.VB6/CR Print Setup Dialog Ex.

  4. #4
    Join Date
    Oct 2006
    Posts
    65

    Re: No. of row effected in Update/Insert Query

    working, u r gr8
    can we do the same for select quries.

  5. #5
    Join Date
    Nov 2004
    Location
    LA. California Raiders #1 AKA: Gangsta Yoda™
    Posts
    616

    Re: No. of row effected in Update/Insert Query

    With a select query you would be opening a recordset with the select statement as your source so you would depend on the .RecordCoutn property if your peovider supports it.
    VB/Office Guru™ (AKA: Gangsta Yoda™)
    VB Forums - Super Moderator 2001-Present

    Microsoft MVP 2006-2011

    Please use [code]your code goes in here[/code] tags when posting code.

    Senior Software Engineer MCP, BSEE, CET
    VS 2012 Premium, VS 6.0 Enterprise SP6, VSTO, Office Ultimate 2010, Windows 7 Ultimate
    Star Wars Gangsta Rap SE Reputations & Rating Posts Office Primary Interop AssembliesAdvanced VB/Office Guru™ Word SpellChecker™.NETAdvanced VB/Office Guru™ Word SpellChecker™ VB6Outlook Global Address ListVB6/Crystal Report Ex.VB6/CR Print Setup Dialog Ex.

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

Featured