26282 total geeks with 3498 solutions
Recent challengers:
 Welcome, you are an anonymous user! [register] [login] Get a yourname@osix.net email address 

Articles

GEEK

User's box
Username:
Password:

Forgot password?
New account

Shoutbox
MaxMouse
It's Friday... That's good enough for me!
CodeX
non stop lolz here but thats soon to end thanks to uni, surely the rest of the world is going good?
stabat
how things are going guys? Here... boring...
CodeX
I must be going wrong on the password lengths then, as long as it was done on ECB
MaxMouse
lol... the key is in hex (MD5: of the string "doit" without the "'s) and is in lower case. Maybe i should have submitted this as a challenge!

Donate
Donate and help us fund new challenges
Donate!
Due Date: May 31
May Goal: $40.00
Gross: $0.00
Net Balance: $0.00
Left to go: $40.00
Contributors


News Feeds
The Register
Curiosity
plunges its drill
into Mars AGAIN,
seeks life-giving
sample
Our new 1.5TB
lappie drive isn"t
thick, it"s just
the densest - HGST
A backdoor into
Skype for the Feds?
You"re joking...
BYOD beyond the
noise
Six things you
should know before
you roll out Office
365
Vodafone revenues
hit as customers in
Europe hang onto
their cash
Space dogs and
Dragons: A brief
history of reentry
tech
Your hot
peer-on-peer code
wrestling could net
$800k from Samsung
Win a Nexus 7 with
reed.co.uk and The
Register
WTF is... LTE
Advanced?
Slashdot
German Researchers
Hit 40 Gbps On
Wireless Link
The Hunt For
LulzSec"s Missing
Sixth Member
Latvian Police Raid
Teacher"s Home for
Uploading $4.00
Textbook
EFF Resumes
Accepting Bitcoin
Donations After Two
Year Hiatus
Google Drops XMPP
Support
Motion To Delay
Sanctions Against
Prenda Lawyers
Denied
NSA Data Center the
Focus of Tax
Controversy
Viruses In Mucus
Protect From
Infection
Reporters
Threatened, Labeled
Hackers For Finding
Security Hole
Judges Debate
Patents and If New
Software Makes a
Computer a "New
Machine"
Article viewer

Writing your own SQL Query Analyser in C#



Written by:bb
Published by:bb
Published on:2004-03-23 09:38:17
Topic:Dot.Net
Search OSI about Dot.Net.More articles by bb.
 viewed 25684 times send this article printer friendly

Digg this!
    Rate this article :
How to write a Windows form in the C# .Net programming language which takes a SQL instruction and dynamically produces a results list in about 7 lines of code.

1) Get a .NET IDE such as VS.NET or SharpDevelop free (google for it)

2) Create a new C# Windows Forms project

3) Add a textbox and button to the top of the form for accepting user input. Set the textbox to be multiline and set the text of the button to 'Execute'

4) Use the Server Explorer to navigate to you database. Highlight the database and drag it onto your workspace (this creates sqlConnection1 binding to the database).

5) Open the Windows forms toolbox and drag a datagrid onto your workspace. This is where the results will be displayed. Align it nicely at the bottom of the form.

6) Double click the Execute button to go to the click event and enter the following code

private void button1_Click(object sender, System.EventArgs e)
{
 //create a new sql command object of type dynamic sql
 SqlCommand cmd = sqlConnection1.CreateCommand();
 cmd.CommandType = CommandType.Text;

 //set the sql command to whatever is in the textbox
 cmd.CommandText = textBox1.Text;

 //create a new data adapter and bind it to the command obejct
 SqlDataAdapter da = new SqlDataAdapter();
 da.SelectCommand = cmd;

 //create a new dataset and fill it with results based adapter
 DataSet ds = new DataSet();
 da.Fill(ds, "Results");

 //bind the local variable dataset to the datagrid on the form
 dataGrid1.DataSource = ds;
 dataGrid1.DataMember = "Results";
}


7) Make sure you have a main method which starts your form (mines called SQLForm).
static void Main()
{
 Application.Run(new SQLForm());
}


8) Run your project and put in a valid sql statement and watch those dynamic results come flooding back. You can call any statement, including executing stored procedures.


Did you like this article? There are hundreds more.

Comments:
think12
2004-03-23 12:31:21
SharpDevelop
Obscurity
2004-03-23 14:01:41
Somewhat off topic, I hope you don't mind BB. I'm thinking of looking into C# coding for Windows Based Applications. How is the ability to use API in C#? And does it require a runtime, like Java?
bb
2004-03-23 14:36:53
it runs inside the microsoft CLR, which comes installed in all machines post xp.

as for api, not really sure what you mean.

gabbana
2004-03-27 15:41:31
I think he's talking about WindowsForms - and this is a "same functionality as with VC++" as an answer.
Anonymous
2006-10-19 10:18:40
Hi,

Can you please tell exactly where to drop the database for some reason i can't drag the database anywhere can you please be more specific on how to drag it.

I'll be looking forward to hear from you soon.

thanks in advance

Sam
Anonymous
2009-08-07 17:05:03
<h1>hello</h1>
ObatAsamUrat
2011-06-16 07:43:36
Hey there Wonderful web site i always aspired to consult, just about any design there's a chance you're employing should it be a no cost Wetpaint Design and style as well as expertise may be reached it which experts claim site have you ever spend on an item through ? Regards
kaos distro
Anonymously add a comment: (or register here)
(registration is really fast and we send you no spam)
BB Code is enabled.
Captcha Number:


Blogs: (People who have posted blogs on this subject..)
bb
ASP.NET RadioButton GroupName when inside a Repeater on Sun 10th Jun 8am
I was thankful on finding this nugget of code, which makes the groupname work out when slamming in radiobuttons in an asp.net repeater. http://www.codeguru.com/csharp/csharp/cs _controls/custom/article.php/c12371/


     
Your Ad Here
 
Copyright Open Source Institute, 2006