0
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)

I execute above command from c# app.

How can I get print message? Im trying like this:

        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)
        }

Anyone could tell me what Im doing wrong?

Tomasz Kaleta
  • 61
  • 1
  • 6

1 Answers1

1

If you use the following query your reader will see the output select.

IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'{0}')
BEGIN
    SELECT '{1}'
END
ELSE
BEGIN
    SELECT 'NOT_OK'
END
Hogan
  • 69,564
  • 10
  • 76
  • 117