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.

 All Forums
 Development Tools
 ASP.NET
 detailed sql results

Author  Topic 

mattatuni
Starting Member

2 Posts

Posted - 2009-03-08 : 16:21:34
Within query analsyer or sql managment studio

if you enter a query and it is success full it will display the result , eg x rows effected or whatever

and 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 site

cheers

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. Gupta
B.Sc. CS, Minor Japanese
MCITP: Database Administrator
MCTS: SQL Server 2005
http://sqllearnings.blogspot.com/
Go to Top of Page

mattatuni
Starting Member

2 Posts

Posted - 2009-03-09 : 17:32:31
how and whee would i use @@rowcount?
Go to Top of Page

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. Gupta
B.Sc. CS, Minor Japanese
MCITP: Database Administrator
MCTS: SQL Server 2005
http://sqllearnings.blogspot.com/
Go to Top of Page
   

- Advertisement -