Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
mattatuni
Starting Member
2 Posts |
Posted - 2009-03-08 : 16:21:34
|
Within query analsyer or sql managment studioif you enter a query and it is success full it will display the result , eg x rows effected or whateverand if you enter a query with an error it it will tell you the error....how can i show the same results when running a query in from my .net app......?catch sql exeption is the closest I can get....is there any other ways of returning results like query analyser and managment express do?I am trying to achieve an application which will allow users to test them selves and learn sql.... im tryin to incorporate a section on the page where they can try out sql statements and see what happens, this will be connected to a different database than my app, which will be locked down to the degre where users can't maliciously try to break the sitecheers |
|
guptam
Posting Yak Master
161 Posts |
Posted - 2009-03-08 : 23:34:08
|
You would have to execute the SQL Statement unless you want to implement a SQL Parser. After executing check the @@Error value to see if there is an error if there is you can get the error message from SQL Server and return that to the user. With SQL Server 2005 you can use Try..Catch block to do this kind of error handling/outputting. And to see how many rows got affected by a delete/insert/update you can use @@ROWCOUNT.Thanks.-- Mohit K. GuptaB.Sc. CS, Minor JapaneseMCITP: Database AdministratorMCTS: SQL Server 2005http://sqllearnings.blogspot.com/ |
|
|
mattatuni
Starting Member
2 Posts |
Posted - 2009-03-09 : 17:32:31
|
how and whee would i use @@rowcount? |
|
|
guptam
Posting Yak Master
161 Posts |
Posted - 2009-03-09 : 23:23:01
|
Well since you want to return results to use on number of records affected; you can execute their code using a stored proc and the last statement in store proc would be SELECT @@RowCount. Thanks.-- Mohit K. GuptaB.Sc. CS, Minor JapaneseMCITP: Database AdministratorMCTS: SQL Server 2005http://sqllearnings.blogspot.com/ |
|
|
|
|
|