Here is an example of each class when connecting to ALTIBASE in the ADO.NET environment. The code used is described based on Visual C#, which is widely used in the ADO.NET environment.
AltibaseConnection
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Altibase.Data.AltibaseClient;
namespace ConsoleApplication1
{
class Program
{
static voidMain(string[] args)
{
String connStr = "DSN=192.168.1.35;uid=sys;pwd=manager;NLS_USE=MS949;PORT=20300";
AltibaseConnection cn = new AltibaseConnection(connStr);
try
{
cn.Open();
Console.WriteLine("connected\n");
}
catch (AltibaseException e)
{
Console.WriteLine(e.Message);
}
Console.ReadLine();
}
}
}
Items used as access information are as follows.
Connection information configuration items | Description |
---|---|
DSN | Physical IP address where ALTIBASE DB server is located |
UID | DB account name
|
PWD | DB account password |
PORT | ALTIBASE Listen Port number |
NLS_USE | Character set for multilingual processing (charset used when creating DB) |
Getting date/time using AltibaseDataReader, AltibaseCommand
This is an example of getting the date/time with Command and DataReader objects.
AltibaseCommand cm;
AltibaseDataReader dr;
try
{
................
................
cn.Open();
Console.WriteLine("connected\n");
cm = new AltibaseCommand();
cm.Connection = cn;
cm.CommandText = "Select to_char(sysdate, 'yyyy-mm-dd hh:mi:ss') from dual";
dr = cm.ExecuteReader();
while (dr.Read())
{
Console.WriteLine(dr.GetString(0));
}
}
catch (AltibaseException e)
{
Console.WriteLine(e.Message);
}
INSERT with AltibaseDataAdaptor
An example of an INSERT with the AltibaseDataAdaptor is described.
AltibaseConnection cn = new AltibaseConnection(connStr);
AltibaseDataAdapter da = new AltibaseDataAdapter();
try
{
.................
cn.Open();
Console.WriteLine("정상적으로 연결됨\n");
da.InsertCommand = new AltibaseCommand("INSERT INTO T1 VALUES (?, ?)", cn);
DataTable t1 = new DataTable();
DataRow r1 = null;
t1.Columns.Add(new DataColumn("C1", typeof(string)));
t1.Columns.Add(new DataColumn("C2", typeof(int)));
da.InsertCommand.Parameters.Add(da.InsertCommand.CreateParameter());
da.InsertCommand.Parameters[0].SourceColumn = "C1";
da.InsertCommand.Parameters.Add(da.InsertCommand.CreateParameter());
da.InsertCommand.Parameters[1].SourceColumn = "C2";
r1 = t1.NewRow();
r1.ItemArray = new Object[] {"hong gi dong", 23};
t1.Rows.Add(r1);
da.Update(t1);
}
AltibaseTransaction
AltibaseCommand cm = new AltibaseCommand();
AltibaseTransaction tx = null;
try
{
cn.Open();
tx = cn.BeginTransaction();
cm.Connection = cn;
cm.CommandText = "insert into t1 values ('viliad', 30)";
cm.ExecuteNonQuery();
tx.Commit();
}
catch (AltibaseException e2)
{
tx.Rollback();
Console.WriteLine(e2.Message);
}