 |
|
|
Calling stored procedure
Last Post 12 Sep 2009 02:30 AM by ananda. 2 Replies.
|
Sort:
|
|
Prev Next |
You are not authorized to post a reply. |
|
ananda
 New Member Posts:28

 |
| 11 Sep 2009 05:09 AM |
|
Hi cmille, Could you clear me one doubts.
{ $con= "server=ipaddress;database=master;User Id=username;Password=password"
select * from table1 select * from table2 select * from table3 ......................... $cmd="select * from table7" $da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $con) $dt7 = new-object System.Data.Datatable $da.fill($dt7) $svr $Reslut7 = $dt7 | out-string
after that below part i want calling stored procedure, how to calling sp here? sp there we don't give parameter value. sp name - exec usp_checksqlservices sp retun value is - SQL Server "servername" is Online for the past 22 hours & 59 minutes MSSQLSERVER SERVICE and SQL AGENT SERVICE both are running
$con = new-object System.Data.SqlClient.SqlConnection $con.Open() $cmd = new-object System.Data.SqlClient.SqlCommand("exec usp_checksqlservices", $con) $cmd.ExecuteNonQuery() $con.Close()
} ...................... .......................
here email part, I have received all table result fine via email, so i want receive table result with sp values. how to add body text on sp return values? { ........ $bodyText = ("$Reslut1","$Reslut2","$Reslut3","$Reslut4","$Reslut5","$Reslut6","$Reslut7","$txt") ....... }
Thanks |
|
|
|
|
Chad Miller
 Basic Member Posts:160

 |
| 11 Sep 2009 01:29 PM |
|
Use the same code to call the stored procedure as you're using for the select query. The method ExecuteNonQuery() should only be used for SQL statements that do not return result sets i.e. insert, update, delete statements. So, you should be able to call the procedure like this $cmd="exec usp_checksqlservices" $da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $con) $dt7 = new-object System.Data.Datatable $da.fill($dt7) $Reslut7 = $dt7 | out-string
|
|
|
|
|
ananda
 New Member Posts:28

 |
| 12 Sep 2009 02:30 AM |
|
Hi Cmille , thanks for your reply I could tried below statement, It return value is 0, $cmd="exec usp_checksqlservices" $da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $con) $dt7 = new-object System.Data.Datatable $da.fill($dt7) $Reslut7 = $dt7 | out-string Thanks |
|
|
|
|
| You are not authorized to post a reply. |
|
Active Forums 4.3
|
|
 |