Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#如何从sql server查询中获取打印输出信息_C#_Sql_Sql Server 2012 - Fatal编程技术网

c#如何从sql server查询中获取打印输出信息

c#如何从sql server查询中获取打印输出信息,c#,sql,sql-server-2012,C#,Sql,Sql Server 2012,我从c#app执行上述命令 如何获取打印消息? 我试着这样做: DECLARE @message VARCHAR(10) IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'{0}') BEGIN SET @message = '{1}' END ELSE BEGIN SET @message = 'NOT_OK' END PRINT(@message) 任何人都可以告诉我我做错了什么

我从c#app执行上述命令

如何获取打印消息? 我试着这样做:

DECLARE @message VARCHAR(10)
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'{0}')
BEGIN
    SET @message = '{1}'
END
ELSE
BEGIN
    SET @message = 'NOT_OK'
END

PRINT(@message)

任何人都可以告诉我我做错了什么?

如果您使用以下查询,您的读者将看到选择的输出

        if(connection.State.ToString() == "Closed")
        {
            connection.Open();
        }
        SqlCommand newCmd = connection.CreateCommand();
        newCmd.Connection = connection;
        newCmd.CommandType = CommandType.Text;
        newCmd.CommandText = string.Format(queriesMgr.getQuery(SqlQueriesID.IS_TABLE_EXISTS), "student", "OK");

        SqlDataReader reader = newCmd.ExecuteReader();


        if (reader.Read())
        {
            //not enter here(no data to read)
        }

使@message成为一个输出参数,例如(“{0}”看起来像一个插值占位符,在T-SQL中没有这种占位符)@AlexK。--正如他所说,这是他的C代码。
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'{0}')
BEGIN
    SELECT '{1}'
END
ELSE
BEGIN
    SELECT 'NOT_OK'
END