0

How do I put this DBMS.OUTPUT_PUT.LINE in a database, and is it also allowed to put it on listbox, datagridview or label?

example: [Time]: "NAME" has inserted a data.

lan smoke
  • 19
  • 2
  • I've got no idea what you are asking. Please explain in (much) more detail. – HoneyBadger Mar 15 '18 at 10:56
  • if you mean `DBMS_OUTPUT.PUT_LINE`; that's Oracle, not SQL Server; are you asking how to do something *like* `DBMS_OUTPUT.PUT_LINE` in SQL Server? What has a db concept like `DBMS_OUTPUT.PUT_LINE` got to do with UI controls like listbox/datagridview? – Marc Gravell Mar 15 '18 at 10:56
  • `DBMS_OUTPUT.PUT_LINE` in Oracle and `PRINT` in Microsoft SQL Server return message text to the client. I guess you could consume those messages to display in a client UI but that's not commonly done. Use `SELECT` statements to return data. – Dan Guzman Mar 15 '18 at 11:05

1 Answers1

1

If you are trying to get additional text data from an operation to be returned from a SQL operation similar to how DBMS_OUTPUT.PUT_LINE works, then PRINT allows that. Since you mention C#, you should note that to consume PRINT data you need to subscribe to the SqlConnection.InfoMessage event, as described here.

However, in most cases it is more suitable / pragmatic to SELECT (perhaps via OUTPUT-clause in the case of INSERT/DELETE operations) something that informs the UI - perhaps the rows, perhaps the @@ROWCOUNT, perhaps the SCOPE_IDENTITY(). PRINT is usually a bad option for anything other than tool scripts.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Then, how could I display a report like this `"@Name" has inserted new data`?? Is there any options like that? – lan smoke Mar 15 '18 at 11:42
  • @Ian to whom are you trying to display it? if you want user X to see things that user Y has done: that isn't going to work - and I don't *think* it would work with `DBMS_OUTPUT.PUT_LINE` either. Usually, output data like this is specific to a single connection, which means user X would be able to see messages caused by commands on user X's connection, but: user X *already knows* the things that they've done, so it serves no purpose – Marc Gravell Mar 15 '18 at 11:53
  • I got enlightened, thank you – lan smoke Mar 15 '18 at 12:11