Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HI

What i am Expecting is that In My text Box if i write Any Sql Query As select or anything and I will perform one button event it should Give me the Output on another label or text box .
So on total
1.text box:Where i write My query
2:Will have same functionality as like execute
3:Text Box Where My executed query Output will be displayed
Posted

My text Box if i write Any Sql Query As select or anything and I will perform one button event it should Give me the Output
I would strongly not suggest this implementation. This is like willingly asking for SQL Injection.
Refer:
MSDN: SQL Injection[^]
SQL Injection Mitigation: Using Parameterized Queries[^]


For database operations, you should use parametrized queries or SP's via ADO.NET.
Refer:
Look here for parameterized query and it's usage:
MSDN: Configuring Parameters and Parameter Data Types (ADO.NET)[^]
MSDN: DataAdapter Parameters (ADO.NET)[^]
MSDN: SqlCommand.Parameters Property [^]
 
Share this answer
 
OK, you can do this but I'm going to want you to read to the end before you do. First, how to do it: I wrote an article a while ago that dealt with how to write T-SQL. I wrote a simple application that took the SQL text you put into the box and it ran it against the database. You can get the source for the application, as well as see a working example here:

SQL for Developers: Basic Data Retrieval[^]

Note that this isn't what the article is about, but there is a working example of what you want to do. The code will be basically the same for ASP.NET (right now it is just a WinForms app). That will get you through the "how" of doing this. Now for a short speech:

I would HIGHLY recommend against doing this. This is a bad idea. If your users can run SQL statements, then they can do things like dropping the table or reading other information that you weren't expecting them to do or executing scripts against the database. Please, please, please don't do this. Figure out a better way to accomplish what you want to do. If you do this, I can almost guarantee you will regret it down the road. Even if you lock down the user account it is running under and only give access to certain employees to run this, at some point someone will make a mistake and someone else will exploit it (intentionally or unintentionally).
 
Share this answer
 
Comments
RAKESH CHAUBEY 15-Aug-12 14:53pm    
Thank you very much TIM COREY ..It resolved the issue ..Thanks a lot .
Could you please Assist with this.
i have a table in my database now i want a mail to be sent automatically from my windows application at certain time .Which contain the detail of those table data in excel Format ...
So what i was thinking Sppse at 11 o clk my database table get updated now at 12 i want to send email to certain user stating this is the todays report It could be excel format or anything and it will happen on daily basis
RAKESH CHAUBEY 15-Aug-12 14:54pm    
It wld be better by using taskscheduler or anything will help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900