A very simple Oracle query tool


A very simple Oracle query tool

Download

Introduction

While working on an Oracle XE project a while back, I developed a simple query tool to allow me to execute sql statements and view the results in a DataGridView control. This functionality was already provided by Oracle APEX, a web application supplied by Oracle XE, which allowed me to enter Sql statements to execute. However it did not list the table structure or table data, which would of helped, while constructing Sql statements. For example, if I wanted to retrieve specific columns from a table, I would need to know what the columns were called. Some times I would forget what a columns was called or how it was spelt, so I would have to go into the object browser and copy the column names. The SQL command interface does not list the tables or show you the table structure. It only allows you to enter SQL statements, if the statement was a SELECT query, it would show you the results of the query.

At times I would need column names from multiple tables, to construct an Sql JOIN statement. For this reason, I developed a simple query application. The application works in the following way. When logged in, a ListView control is populated when the "List Tables" button is clicked, showing the tables that belong to the user logged in. By selecting a table name from the ListView control, you can view the structure of the table. By clicking the appropriate buttons you can switch between structure view or data view. The structure view will show the data types for each column. By switching to data view, you can see the data stored in each column. While constructing an SQL statement, you can easily view the table structure or the data. I have also included the ability to List VIEWS. You can see the structure of a VIEW as well as the data the VIEW will produce.

Below is a few screen shots of the working program. Figure 1.1 below shows the login form. This form requires that you enter the data source name, user id and passwrord.

Figire 1.1
Screenshot - img1.jpg

After loggin in, you will be presented with the following form (Figure 1.2).

Figure 1.2
Screenshot - img2.jpg
Figure 1.3
Screenshot - img3.jpg
Figure 1.4
Screenshot - img4.jpg

The Code

I have seperated the connection to the database code from the UI code. orcConnection Class contains a Connect() Method, which connects to the database. Listing 1.1 below shows the Connect() method.

Listing 1.1
public static string Connect(string strDataSource, string strUserId, string strPassword)
{
string strConResult = "";

string orcConString = "Data Source=" + strDataSource + ";User Id=" + strUserId + ";Password=" + strPassword + ";";
orcCon = new OracleConnection(orcConString);

try
{
orcCon.Open();
}
catch (OracleException orcEx)
{
strConResult = "An error occured: " + orcEx.Message;
}

return strConResult;
}

The Connect() method, takes three arguments, a data source, user id and password all of type string. I have used a try/catch block to catch any errors. If any errors are produced, the error message is returned to the calling method, where it is displayed in a message box.




1 Simple DataGridView Example - C#
This example demonstrates how to load data into the DataGridView control using string array's.
2 A Custom Message Box - C#
This example source code demonstrates how you can develop your own messages box.
3 Custom MessageBox 2 - C#
This example source code builds on a previous example of creating a custom MessageBox. New features in this example include different types of buttons and displaying an icon. Also uses different message beep tones for standard MessageBox's and warring MessageBox's.
4 Connect To MSN Messenger Using The MSN Protocol - C#
This sample application demonstrates how to connect to MSN Messenger using the MSN Protocol. It also includes how to generate a Ticket that is used with the ChallengeString. This is a simple authentication example.
5 Send Messages Using The Net Send Command - C#
This sample program demonstrates how to send messages in a network using the Windows Messenger service.
1 Transfer data from CSV file to MySQL - Java
This snippet transfers deliminated data from a CSV file to a MySQL database. You need to edit the code to include your database connection details and also the fields from the CSV and MySQL needs to correspond with your fields.
2 Read Image File As bytes - C#
This sinppet opens an image for reading as bytes. The bytes are then placed into a memorystream which is used to create a bitmap image of the bytes. The image is then set as the forms background image.
3 Retrieve the path of a file, using openfiledialog - C#
This snippet uses the openfiledialog class to get a files path. Useful for opening files from a location on the harddrive.
4 Load web image into picturebox - Visual Basic.Net
Function with picturebox and url as argument to display the passed url to image inside a picturebox I got this from freevbcode a while back.
5 Random Number Generator - Visual Basic.Net
Function that reurns a random non-repeating integer
CY2 Online2.net | CopyRight 2005 - 2008 | All Rights Reserved