Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Running stored procedures/copying results in VB.net
Message
From
21/09/2011 11:18:40
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01524129
Message ID:
01524148
Views:
43
>>>>I'm trying to automate a task here. Right now I have to run two SPs (one updates a table, the other displays the table), copy the data from the second one, and paste it into an e-mail to send to numerous people. I took care of generating the e-mail, but I need help running the stored procedures. I don't need to see the data anywhere, I just need them both to run and have it copy the output automatically.
>>>>
>>>>I tried Googling but I keep seeing a bunch of different ways to execute a store procedure. I started off with this but then saw examples that were way more involved, so I didn't think this was the right start:
>>>>
>>>>
 Dim SQLCon As New SqlClient.SqlConnection
>>>>        SQLCon.ConnectionString = "Data Source=name;Integrated Security = True;"
>>>>        SQLCon.Open()
>>>
>>>I think you're on the right track if you want to use ADO.NET. Usually you don't specify connectionstring in the app directly, you read it from the config file. For now it will be OK. So, just use the sample you found - you need to add creation of the command object, parameters and then use ExecuteNonQuery method of the Command object.
>>
>>As far as parameters go, neither SP has any, they just run as soon as you click "execute".
>>
>>The example I was looking at told me to use CommandText as below:
>>
>>
Dim SQLCon As New SqlClient.SqlConnection
>>        Dim SQLCmd As New SqlCommand
>>
>>        SQLCon.ConnectionString = "Data Source=name;Integrated Security = True;"
>>        SQLCon.Open()
>>
>>        SQLCmd.CommandText = "Exec StandardNamesUpdate"
>>        SQLCmd.Connection = SQLCon
>>
>>I don't think that's working though. I'll try to look into the ExecuteNonQuery method.
>
>The above is not very good example. Try this one (first result in BING):
>http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson07.aspx
>
>Using Google also doesn't seem to bring good VB.NET examples - all examples I found so far were C#. Anyway, another one
>http://www.codeproject.com/KB/cs/simplecodeasp.aspx


The second link was pretty badly formatted and looks to have incorrect code in places, but I mixed and matched some stuff and came up with this:
SQLCon.ConnectionString = "Data Source=server;Initial Catalog=database;Integrated Security = True;"
        SQLCon.Open()
        SQLCmd = New SqlCommand("StandardNamesUpdate", SQLCon)
        SQLCmd.CommandType = CommandType.StoredProcedure
        SQLCmd.ExecuteNonQuery()
        SQLCon.Close()
When I run the program it pauses about as long as it takes for the SP to run in SQL Server, and then my e-mail is generated so it may be working. Now I need a way to check to see if it's working for sure, can I assign it to a text box and have it show me the number of rows affected? After that, how do I get it to copy the results of the second SP so I can have it pasted into the e-mail?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform