Working with Sybase Databases using ADO.NET


This article has been excerpted from book "A Programmer's Guide to ADO.NET in C#".

You can access a Sybase database using the OleDb data adapter provider. The only thing you need to do is to set up an ASO OLE DB provider data source. As you can see from listing 11-12, I created a data source called sydev with the user ID tiraspr and the password tiraspr. After creating a connection, you use the same steps to access the database as described previously. I selected data from the user_tree_start table and used it to create a command object. After that I called ExecuteReader to execute the string and fill data in a reader.

Listing 11-12: Accessing a Sybase database

using System;
using System.Data;
using System.Data.OleDb;

namespace AccessSybase
{
    class Class1
    {
        static void Main(string[] args)
        {
            string connectionString, sql;
            OleDbConnection conn;
            OleDbDataReader rdr;
            OleDbCommand cmd;
            connectionString =
            "Provider=Sybase ASE OLE DB Provider;Datasourcce=sydev;" + "User ID=tiraspr;Password=tiraspr";
            conn = new OleDbConnection(connectionString);
            conn.Open();

            sql = "Select * from user_tree_start";
            cmd = new OleDbCommand(sql, conn);
            cmd.CommandType = CommandType.Text;
            rdr = cmd.ExecuteReader();

            while (rdr.Read())
                Console.WriteLine(rdr["user_id"].ToString() + " " + rdr["tree_start"] + " " + rdr["strategy_group"]);

            Console.WriteLine("DONE");
            Console.Read();
        }
    }
}

Conclusion

Hope this article would have helped you in understanding working with Sybase Databases using ADO.NET. See my other articles on the website on ADO.NET.

adobook.jpg
This essential guide to Microsoft's ADO.NET overviews C#, then leads you toward deeper understanding of ADO.NET.

Up Next
    Ebook Download
    View all
    Learn
    View all