How do i create an SQL viewer using ASP.NET in C#

Posted on 2009-02-18
Last Modified: 2013-12-18
Hi i'm a newbie to C# programming and i am trying to create an SQL command viewer same as ISQL * Plus using Visual Studio 2005 in C#

I have a database created using SQLDataSource which is called customer. It contains ID, firstname, surname, address. This is linked to a Gridview which display the information within the database.

Want i want is to bind the textbox some how to the database or Gridview so when the user type in any SQL command/statement via the textbox such as "SELECT firstname from Customer; or "INSERT INTO customer(firstname,surname,adress) VALUES ('Alan','Smith','Boston')  It will show the results in the Gridview.

However, i want some type of validation to ensure the SQL command entered by the user is correct and is shown to the user.For example In a form of an error message on the web page stating either correct or incorrect if they miss out the ; <-- (cant remember what you call it again)

I would also like to expand this by allowing the user to create a database using the text box and perform othe SQL statement such as SQL ORDER BY, SQL DELETE, SQL UNION,SQL GROUP BY etc

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >

<head runat="server">

    <title>SQL Viewer</title>



    <form id="form1" runat="server">


        <span style="font-size: 10pt; font-family: Tahoma">Select only the firstname and address

            from the table</span><span style="font-size: 10pt; font-family: Tahoma"><br />

            <br />

            Enter SQL Command below:<br />

        </span><br />

        <br />

        <br />

        <asp:TextBox ID="TextBox1" runat="server" Height="184px" Style="z-index: 103; left: 8px;

            position: absolute; top: 72px" Width="504px" TextMode="MultiLine"></asp:TextBox>

        <br />

        <br />

        <br />

        <br />

        <br />

        <br />

        <br />

        <br />

        <asp:GridView ID="GridView1" runat="server" Style="z-index: 101; left: 8px; position: absolute;

            top: 392px" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">


                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"

                    SortExpression="ID" />

                <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />

                <asp:BoundField DataField="Surname" HeaderText="Surname" SortExpression="Surname" />

                <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />



        <asp:Button ID="Button1" runat="server" Style="z-index: 102; left: 8px; position: absolute;

            top: 272px" Text="Execute" />

        <br />

        <br />

        Message to the user<br />

        <br />

        <br />

        Results of the query<br />

        <br />

        <br />

        <br />

        <br />

        <br />

        <br />

        <br />

        <br />

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Customer]"></asp:SqlDataSource>






Open in new window

Question by:michael2009
    LVL 15

    Expert Comment

    by:Praveen Venu
    There is already a free tool from micdrosoft available

    Microsoft SQL Web Data Manager

    Author Comment

    Many thanks for your reply. However i still need this done in C# a tutorial or the code maybe
    LVL 15

    Accepted Solution


    Author Comment

    praveenvenu thanks for that i'm examining the code and get back to you. I'm doing a task for work hence the reason i need the code

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Refresh page ASP.NET C# 3 39
    Pick image, show data 4 25
    varchar (max) 5 22
    Pl/SQL Query 31 40
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
    Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
    This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now