It is best to use the output parameter.
@text nvarchar(1000) OUTPUT, @text output.
SET @text = 'This is line 1.' + CHAR(13)+CHAR(10) + 'This is line 2.'
: : , , , , . , , @name, .Value
2: -
SqlParameter text = new SqlParameter("@name", SqlDbType.NVarChar);
text.Direction = ParameterDirection.Output;
cmd1.Parameters.Add(text);
con.Open();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd1);
da.Fill(dt);
con.Close();
MessageBox.Show(text.Value);
, , .
3: . #:
using (SqlConnection connection = new SqlConnection(@"Data Source=.\SQLExpress;Initial Catalog=TestDB;Integrated Security=True"))
{
connection.Open();
using (SqlCommand command = connection.CreateCommand())
{
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "Test";
SqlParameter text = new SqlParameter("@Text", SqlDbType.NVarChar, 1000);
text.Direction = ParameterDirection.Output;
command.Parameters.Add(text);
using (DataTable dt = new DataTable())
{
using (SqlDataAdapter da = new SqlDataAdapter(command))
{
da.Fill(dt);
}
}
Trace.WriteLine(text.Value);
connection.Close();
}
}
:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE Test
@Text Nvarchar(1000) OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SET @Text = 'test'
END
GO
, .
4: @text ,
ALTER PROCEDURE [dbo].[AdminDevUserCreate]
@SQLLoginName varchar(50),
@SQLLoginPass varchar(50)
AS
DECLARE @text NVARCHAR(1000)OUTPUT
ALTER PROCEDURE [dbo].[AdminDevUserCreate]
@SQLLoginName varchar(50),
@SQLLoginPass varchar(50),
@text NVARCHAR(1000) OUTPUT
AS
SqlParameter
SqlParameter text = new SqlParameter("@Text", SqlDbType.NVarChar, 1000);
, , NVARCHAR(1000)
PRINT @text
Select @text