Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL PRINT

Status
Not open for further replies.

johnc83

Technical User
Jan 29, 2008
154
0
0
GB
Hi,

I am trying to get an output from an SQL update command to appear on my VB.NET form but at the moment I am very much at the basics and have one question please..

Example: Lets say I have the following table (tblUsers), it has 2 fields and the current data looks like this:

UserName, Password
John, sex
Paul, drugs
Ringo, rock
George, roll

lets say I want to change everyones password to 'NewPassword'. How do I write an update command so that when it has finished I have the following messages:

John - Update Successful
Paul - Update Successful
Ringo - Update Successful
George - Update Successful

Basically I want to be able to show my user(s) which people have been updated. I know you need to put 'PRINT' somewhere in the code but that is as far as my knowledge stretches.

Would someone mind showing me how please?

Thanks

John

.NET 2.0, Visual Studio 2005, SQL Server 2005 Express
 
Database servers aren't really designed to that sort of thing, John. The core engine doesn't have a user interface component, in the sense that you might think it does. True, there is the PRINT statement, but I've never used it for anthing other than as a debug aid.

We can probably come up with some gyrations that approximate what you are trying to do, but a better approach is for you to rethink this.

If you issue
Code:
update tblUsers set password = 'NewPassword'
and get back no errors (@@error=0) and a @@rowcount that is non-zero, then I think it is safe to assume success. SQL works on a set-basis rather than a row-basis, so there isn't really a simple way to force it to report things on a row-by-row basis.

--------------
SQLS metasearch
 
Hi foxdev, thanks for the reply.

I thought that might be the case.

I'm going to have to rethink how I want this part of my app to work but at least I know whats possible and what isn't - that will save me time instead of searching for something that doesn't even exist!

Thanks again..

John

.NET 2.0, Visual Studio 2005, SQL Server 2005 Express
 
In SQL 2005 you can get the results of an update or delete back as a rowset...
 
You would use the [google]SQL Server OUTPUT clause[/google].



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top