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

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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <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">
            <Columns>
                <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" />
            </Columns>
        </asp:GridView>
        <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>
    
    </div>
    </form>
</body>
</html>

Open in new window

michael2009Asked:
Who is Participating?
 
Praveen VenuTechnical Project ManagerCommented:
0
 
Praveen VenuTechnical Project ManagerCommented:
There is already a free tool from micdrosoft available

Microsoft SQL Web Data Manager
----------------------------------------------------

http://www.microsoft.com/DownLoads/details.aspx?FamilyID=c039a798-c57a-419e-acbc-2a332cb7f959&displaylang=en
0
 
michael2009Author Commented:
Many thanks for your reply. However i still need this done in asp.net C# a tutorial or the code maybe
0
 
michael2009Author Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.