Results 1 to 7 of 7

Thread: Copying SP results to clipboard

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2008
    Posts
    240

    Copying SP results to clipboard

    This is kind of a two part question. I'm trying to make a very simple automated program that will run two stored procedures (one that updates, one that displays the new results) and then copies the results to the clipboard and pastes it in a new e-mail. I already have the e-mail generating and grabbing whatever is on the clipboard, but I need help with the store procedures.

    Every guide I look at on Google seems to show a slightly different way of working with SQL, but I threw this together and need to know if it's working. I don't get any errors and the program "hangs" about as long as it takes for the actualy SP to run, but how do I get the "rows affect" output into a textbox or something?

    Code:
    Dim SQLCon As New SqlClient.SqlConnection
    Dim SQLCmd As New SqlCommand
    
    SQLCon.ConnectionString = "Data Source=server;Initial Catalog=DB;Integrated Security = True;"
            SQLCon.Open()
            SQLCmd = New SqlCommand("StandardNamesUpdate", SQLCon)
            SQLCmd.CommandType = CommandType.StoredProcedure
            SQLCmd.ExecuteNonQuery()
            SQLCon.Close()

  2. #2
    Member
    Join Date
    May 2011
    Posts
    38

    Re: Copying SP results to clipboard

    ExecuteNonQuery() will return the number of rows affected.
    Just save it in a variable and use it to set your textbox's text, copy it to clipboard, or whatever.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Copying SP results to clipboard

    well.... if you read the documentation for ExecuteNonQuery you would find that it states:
    Quote Originally Posted by MSDN
    Executes a Transact-SQL statement against the connection and returns the number of rows affected.
    (emphasis added)

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2008
    Posts
    240

    Re: Copying SP results to clipboard

    I know ExecuteNonQuery returns the number of rows affected, apparently I had a brain fart as to how to get it in the text box. Thanks.

    The bigger question is the second SP, having it copy the results to the clipboard...
    Last edited by ohok; Sep 21st, 2011 at 11:15 AM.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2008
    Posts
    240

    Re: Copying SP results to clipboard

    I used this for the second SP:

    Code:
    SQLCmd = New SqlCommand("StandardNamesCount", SQLCon)
            SQLCmd.CommandType = CommandType.StoredProcedure
            SQLCmd.ExecuteReader()
    The end goal here is to not even see the results, just have them generate in the background and get copied to the clipboard. I also put a GridView on the form and can see the data, but I have no clue how to copy it via code.

  6. #6
    Member
    Join Date
    May 2011
    Posts
    38

    Re: Copying SP results to clipboard

    It's pretty easy to do with a DataGridView, try this:
    VB.NET Code:
    1. DataGridView1.SelectAll()
    2.         Dim content As DataObject = DataGridView1.GetClipboardContent()
    3.         Clipboard.SetDataObject(content, True) '2nd argument makes the data available after the app exits

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2008
    Posts
    240

    Re: Copying SP results to clipboard

    Funny, I just stumbled upon that myself, only I did it a little differently:

    Code:
    Me.StandardNamesCountTableAdapter.Fill(Me.TBLMasterDataSet.StandardNamesCount)
            Me.DataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText
            Clipboard.SetDataObject(Me.DataGridView1.GetClipboardContent)
    I just came back to ask how to select it all, but looks like yours does that I'll try it and let you know.


    EDIT: Yep, that works great, thanks.

    One other small thing, any ideas about a progress bar? I know it's hard to make an accurate one so I was going to do the Marquee style, but as soon as the form loads, the bar is already moving.

    Bah, never mind, I'll just make the cursor do the circle waiting thing.
    Last edited by ohok; Sep 21st, 2011 at 02:25 PM.

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