JG Vimalan's Blog

It is all about coding!

Using Borland BdpParameter

The following code snippet will give you an idea on coding with BdpParameter, 

       public int GetEmployeeCountByGrade(int gradeValue)
        {
            Borland.Data.Provider.BdpCommand command = new
                Borland.Data.Provider.BdpCommand();
            command.CommandText = string.Format(
                “SELECT COUNT(*) FROM {0} WHERE {0}.{1} = ?”,
                Employee,     // 0
                Grade // 1
            );
            Borland.Data.Common.BdpParameter parameter = new 

            Borland.Data.Common.BdpParameter(
                “GRADE”,
                Borland.Data.Common.BdpType.Int32
            );
            parameter.Value = gradeValue;
            command.Parameters.Add(parameter);
            command.Connection = this.Connection;
            return (int)command.ExecuteScalar();
        }

Advertisements

October 9, 2009 Posted by | Interbase | Leave a comment

Connecting to an Interbase database using Enterprise Library 3.1

Inorder to connect to Interbase using Enterprise Library 3.1, the following steps should be followed.

1. Install ADO.NET 2.0 Driver for InterBase (I installed AdoDbxCleint, which is available over internet)

2. Edit the machine.config file from the C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG directory. Add the following line in the section labeled

<DbProviderFactories>

<add name = “Interbase ADO 2.0 provider” …… (This you can find when you install the provider)>

3. Launch Enterprise Library Configuration (you need to install Enterprise library for this)

4. Configure new Data Access Application block as shown below.

Steps

5. So, when you save this, you will get a .config file.

6. Add this config file in your project.

7. Add the following references in your project to make use of Enterprise Library DAL

Microsoft.Practices.EnterpriseLibrary.Common; Microsoft.Practices.EnterpriseLibrary.Data;

8. Put a simple code:  

Database db = DatabaseFactory.CreateDatabase();

string sql = “SELECT Name, Age FROM STUDENT”;

DbCommand command = db.GetSqlStringCommand(sql);

using (IDataReader reader = db.ExecuteReader(command))

{

while (reader.Read())

{

record.SubItems[0].Text = reader[0].ToString();//Get Name record.SubItems[1].Text = reader[1].ToString();//Get Age ….

}

reader.Close();

}      

 Thats all!!!

Happy coding…

 Regards,

JG Vimalan

September 27, 2009 Posted by | Interbase | Leave a comment

Fetch only the column names from an Interbase database table.

The following sql query will fetch the columns name from the specified table in an Interbase database. 

select RDB$FIELD_NAME from rdb$relations r join rdb$relation_fields rf on
r.rdb$relation_name = rf.rdb$relation_name and
r.rdb$relation_name = ‘TABLE NAME’ 

Regards,

JG Vimalan

August 6, 2009 Posted by | Interbase | Leave a comment

Check if a column exists and then delete in an Interbase table

The following query will check if a column already exists in an Interbase database table and then deletes it.

DELETE from RDB$RELATION_FIELDS where RDB$RELATION_Name = ‘TABLE NAME’ and RDB$Field_name = ‘FIELD TO DELETE’

August 6, 2009 Posted by | Interbase | Leave a comment