标签:list static auto oid 行数据 ESS pre main 读取
前提需要安装HANA Windows Client
在CMD中用odbcad32.exe打开ODBC驱动管理程序
配置完成后,测试连接成功,就可以读取HANA数据库了
public class HanaHelp
{
public HanaHelp() { }
public OdbcConnection getConnection()
{
String connStr = "Driver={H00};ServerNode=0.0.0.0:xx;uid=aa;pwd=password;DatabaseName=xx";
var conn = new OdbcConnection(connStr);
return conn;
}
public DataTable ListAll()
{
try
{
OdbcConnection conn = this.getConnection();
String sql = "SELECT * FROM VBAP";
conn.Open();
Console.WriteLine($"当前HANA数据库状态{conn.State}");
Console.WriteLine($"当前连接的HANA数据库服务器的版本{conn.ServerVersion}");
var TableName = sql.Split(‘ ‘)[3];
Console.WriteLine($"当前要读取的数据库表:{TableName}");
OdbcCommand selectCmd = new OdbcCommand(sql, conn);
var adapter = new OdbcDataAdapter(selectCmd);
DataTable employeeTable = new DataTable("employees");
adapter.Fill(employeeTable);
conn.Close();
return employeeTable;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return null;
}
}
}
class Program
{
static void Main(string[] args)
{
HanaHelp command = new HanaHelp();
DataTable a = command.ListAll();
if (a != null)
{
Console.WriteLine("读取到第一行数据为:");
for (int i = 0; i < a.Rows[0].ItemArray.Length; i++)
{
Console.Write(a.Rows[0].ItemArray[i]+" ");
}
}
Console.ReadKey();
}
}
标签:list static auto oid 行数据 ESS pre main 读取
原文地址:https://www.cnblogs.com/fuchj/p/10417900.html