|
-
Sep 21st, 2011, 10:37 AM
#1
Thread Starter
Addicted Member
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()
-
Sep 21st, 2011, 10:59 AM
#2
Member
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.
-
Sep 21st, 2011, 11:01 AM
#3
Re: Copying SP results to clipboard
well.... if you read the documentation for ExecuteNonQuery you would find that it states:
 Originally Posted by MSDN
Executes a Transact-SQL statement against the connection and returns the number of rows affected.
(emphasis added)
-tg
-
Sep 21st, 2011, 11:06 AM
#4
Thread Starter
Addicted Member
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.
-
Sep 21st, 2011, 01:34 PM
#5
Thread Starter
Addicted Member
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.
-
Sep 21st, 2011, 01:44 PM
#6
Member
Re: Copying SP results to clipboard
It's pretty easy to do with a DataGridView, try this:
VB.NET Code:
DataGridView1.SelectAll()
Dim content As DataObject = DataGridView1.GetClipboardContent()
Clipboard.SetDataObject(content, True) '2nd argument makes the data available after the app exits
-
Sep 21st, 2011, 01:50 PM
#7
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|