RecentComments

Comment RSS

Connecting to a PARADOX DB with C# (Vista, XP)

by Ioannis 28. November 2008 23:46

You have a Paradox DB deployed in C:\PARADOXDB\ and you want to connect through C#. Here are the steps that you need to follow:

  1. Dowload BDEInfo.exe which contains the Borland Database Engine (BDE 5.0.2) and a configuration utility.
  2. Install BDEInfo.exe. If no error occurs proceed to step 4. If you get an error message complaining the "BDE already is in memory...." proceed ot step 3.
  3. Locate either in C:\WINDOWS\TEMP\ or the Temp user's folder and locate any file named inmem###.rem and delete it. You need also to find whether there is a folder in C:\PROGRAM FILES\BORLAND\ which a contains a previous installation of BDE and erase it also.
  4. Now BDE is installed.
  5. Create within the C:\PARADOXDB\ folder a folder named LOCKFILES.
  6. Open BDEADMIN.EXE located in C:\PROGRAM FILES\BORLAND\BDE or your installation folder and go to Configuration/Drivers/Native/PARADOX and change the NET DIR entry to C:\PARADOXDB\LOCKFILES\.
  7. Go to Object and click Apply.
  8. Change the file permissions of the LOCKFILES folder for the user "NETWORK SERVICE" to full control.

Now the BDE engine is up and running and you are ready to connect. Create a new C# application and choose one of the following snippets.

To connect:

private bool OpenConnection()

      OleDbConnection _connection = new OleDbConnection(); 
      StringBuilder ConnectionString = new StringBuilder("");
      ConnectionString.Append(@"Provider=Microsoft.Jet.OLEDB.4.0;");
      ConnectionString.Append(@"Extended Properties=Paradox 5.x;");
      ConnectionString.Append(@"Data Source=C:\PARADOXDB\;");
      _connection.ConnectionString = ConnectionString.ToString();
      try { _connection.Open(); }
      catch (Exception e) { MessageBox.Show("Error openning database! "+e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; }
      return true;
}


To open a table in a datagridview (eg the table CLIENTS):

OpenConnection();
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM CLIENTS;", <Connection object>);
DataSet dsRetrievedData = new DataSet();
da.Fill(dsRetrievedData);
this.dataGridView1.DataSource = dsRetrievedData;
this.dataGridView1.DataMember = dsRetrievedData.Tables[0].TableName;


Since the process of finding out what was wrong with connecting to the PARADOXDB took me some time there may be some steps that were useful and not mentioned here. Please leave a comment is this worked for you. If not I can suggest some other stuff I have tried and may have been also useful and forgot to mention them.

 kick it on DotNetKicks.com

Tags:

.NET | Databases

Displaying a custom Icon on the Toolbox for a Custom Control

by Ioannis 20. November 2008 01:00

Let's say you have created a nice Custom Control named "LimitedListTextBox". This control should now appear on the Toolbox with a "gear" icon. If you want to supply your own icon you must do the following:

Create or add a new item to the project. The item should be a Bitmap Image with the same name as the control (in our case LimitedListTextBox.bmp) and should be located (for the easiest case) at the same folder the code fort the control resides.The bitmap should be 16x16 with 16 colors (4bit) and should be defined as an "Embedded Resource" for the project. Below is an example for the LimitedListTextBox Control:



Now go ahead and add the following code just above the definition of the Custom Control's class:

[ToolboxItem(true)]
[ToolboxBitmapAttribute(typeof(LimitedListTextBox),"LimitedListTextBox.bmp"]
public partial class: UserControl
{
     /// Your code here
}


The default icon now will be changed. Note that the control's icon does not show on solutions that contain the project for the control. You only see the icon after you have created the Release/Debug binary version of the control library and imported it from another project as a .dll assembly.

Tags:

.NET | Controls

Finding the property that called a method.

by Ioannis 11. November 2008 01:28
There are some cases where we want to call the same method from the getters/setters of the properties of a business object. Within that method we want to differentiate behaviour according to the property that called the metthod. The most straightforward solution is to pass with the method a string parameter with the property's name.

class myBO
{
     private int _id;
     public int Id
     {
             get { return _id;}
             set { _id=value; PropertyChanged("Id");}
     }

     private string _name;
     public string Name
     {
             get { return _name;}
             set { _name=value; PropertyChanged("Name");}
     }

     private void PropertyChanged(string propertyName)
     {

               // Do some work here based on which property called the method
     }
}

We can avoid passing the property's name as  a parameter and discover that, within the PropertyChanged method. We use the System.Diagnostics assembly to do the following:

class myBO
{
     private int _id;
     public int Id
     {
             get { return _id;}
             set { _id=value; PropertyChanged();}
     }

     private string _name;
     public string Name
     {
             get { return _name;}
             set { _name=value; PropertyChanged();}
     }

     private void PropertyChanged()
     {
               String propname = new System.Diagnostics.StackTrace().GetFrame(1).
                                                  GetMethod().Name.Substring(4);

               // Do some work here based on which property called the method
     }
}

The GetMethod() method returns the method that called this method. We need its name so we access the "Name" property. But why do we select the substring from position 4 to the end? This is because the .NET framework translates the getters and setters of the properties internally to methods named get_PropertyName and set_PropertyName. Since we need to get the property name we omit the "get_" and "set_" and thus select the string from position 4 to the end.

This approach can be used without the Substring() methd in any situation where we need to find out at runtime the method that called another method.

Tags:

.NET

Powered by BlogEngine.NET 1.5.0.7

Programming Blogs - BlogCatalog Blog Directory Add to Technorati Favorites

MVP Award

Ioannis Panagopoulos





This blog is using BlogEngine.Net and is hosted in the hoster below. I have not experienced any problems installing BlogEngine.Net in the host and I am satisfied with the host's response times. Therefore I recommend it.


DiscountASP Add