Hi,
I'm trying to get a set string value from stored procedure to display it in C# label but i getting lost how to do it.
In the stored procedure the value is set to:
- @StaticSQL VARCHAR(250)
- .
- .
- .
- .
- .
-
- SET @StaticSQL = XXXXXXXX
- .
- .
- .
- .
- .
- ETC
DB_Access.cs:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Data;
- using System.Data.SqlClient;
- using System.Windows.Forms;
- using System.Diagnostics;
-
- namespace alerts_operations
- {
- class DB_Access
- {
- SqlConnection conn;
- public DB_Access()
- {
- conn = DB_Connection.GetConnection();
- }
-
- public void ExecuteAlert(string rundate, string alertdate)
- {
-
-
- string ReturnValue = string.Empty;
- if (conn.State.ToString() == "Closed")
- {
- conn.Open();
- }
- SqlCommand newCmd = conn.CreateCommand();
- newCmd.Connection = conn;
- conn.FireInfoMessageEventOnUserErrors = true;
- newCmd.CommandType = CommandType.StoredProcedure;
- newCmd.CommandText = "dbo.sp_static_alerts_call_mailer";
- SqlParameter param1 = new SqlParameter("@RunDate", SqlDbType.VarChar);
- param1.Value = rundate;
- newCmd.Parameters.Add(param1);
- SqlParameter param2 = new SqlParameter("@alertdate", SqlDbType.VarChar);
- param2.Value = alertdate;
- newCmd.Parameters.Add(param2);
- newCmd.CommandTimeout = 0;
- SqlParameter retval1 = newCmd.Parameters.Add("@StaticSQL", SqlDbType.NVarChar,250);
- retval1.Direction = ParameterDirection.Output;
- newCmd.ExecuteScalar();
- string returns = newCmd.Parameters["@StaticSQL"].Value.ToString();
- Debug.WriteLine(retval1);
- MessageBox.Show(returns);
-
-
-
-
-
- }
frmRunAlert.cs: