We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


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

Medium Priority
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<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

Watch Question

Praveen VenuTechnical Project Manager

There is already a free tool from micdrosoft available

Microsoft SQL Web Data Manager



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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.