?
Solved

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

Posted on 2009-02-18
5
Medium Priority
?
379 Views
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>
</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

0
Comment
Question by:michael2009
  • 2
  • 2
4 Comments
 
LVL 15

Expert Comment

by:Praveen Venu
ID: 23678926
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
 

Author Comment

by:michael2009
ID: 23680663
Many thanks for your reply. However i still need this done in asp.net C# a tutorial or the code maybe
0
 
LVL 15

Accepted Solution

by:
Praveen Venu earned 2000 total points
ID: 23683888
0
 

Author Comment

by:michael2009
ID: 23687370
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

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

839 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