Welcome

Welcome to my blog. Here you can find few tips about Microsoft Dynamics NAV.

Wednesday 18 April 2012

Fetching values from tables in navision with NODBC

As we know the NODBC can help us to access data in navision without opening the application. The Code for fetching the values from the customer table is posted below.

We can use the native database and the native server only in the NODBC . First we need to install the NODBC in the CD of the installation file.
 
Go to control panel-->Administrative tools-->ODBC. 

The ODBC will open for you. Search for the Microsoft Dynamics NAV Driver. It may be in "USER DSN" or some times in "System DSN". We can able to find the above driver.

Click Add, you will ask you to create a new data source.

Choose "Microsoft Dynamics NAV Driver" in the list and then click "Finish".

The ODBC Setup page will open for you. In the page you need to specify the data source and that acts as a DSN.

If your database is Local, you can specify the local database or choose server.

If you choose server, you need to specify the server you are having the database.

We need to choose the database if it is a local server else the database is not editable.
also we need to specify the credentials, Company name and if needed we need to import license also.

click ok. 

Code for fetching the values:

I have done the code in the console application. 

using System.Data.Odbc;
namespace ConsoleApplication3
{
    class Program
    {
       
        static void Main(string[] args)
        {
            string word;
            OdbcConnection con = new OdbcConnection("DSN=NewDemoDatabase;Server='';UID=reka;Database=D:\\d\\Demo database\\Demodb.fdb;");
            OdbcCommand cmd = new OdbcCommand("select * from Customer", con);
            con.Open();
            OdbcDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                 word=reader.GetString(1);
                 Console.WriteLine(word);
            }
           
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment