Que Necesitas?
- Un Compilador de C#
- La Plataforma .NET
- Microsoft ODBC.NET
- Una Fuente de Datos ODBC a una Base de Datos PostGRESQL.
CREATE TABLE vbtest(
id serial,
data text,
accessed timestamp
);
INSERT INTO csharptest(data, accessed) VALUES('Rows: 1', now());
INSERT INTO csharptest(data, accessed) VALUES('Rows: 2', now());
INSERT INTO csharptest(data, accessed) VALUES('Rows: 3', now());
Codigo de Ejemplo
using System;
using System.Data;
using Microsoft.Data.Odbc;
class psqlODBC_Howto
{
[STAThread]
static void Main(string[] args)
{
string szConnect = "DSN=dsnname;" +
"UID=postgres;" +
"PWD=********";
OdbcConnection cnDB = new OdbcConnection(szConnect);
try
{
cnDB.Open();
}
catch (OdbcException ex)
{
Console.WriteLine (ex.Message + "\n\n" + "StackTrace: \n\n" + ex.StackTrace);
Console.WriteLine("\nPress to continue...");
Console.Read();
return;
}
DataSet dsDB = new DataSet();
OdbcDataAdapter adDB = new OdbcDataAdapter();
OdbcCommandBuilder cbDB = new OdbcCommandBuilder(adDB);
adDB.SelectCommand = new OdbcCommand(
"SELECT id, data, accessed FROM csharptest",
cnDB);
adDB.Fill(dsDB);
Console.WriteLine("Table 'csharptest' contains {0} rows.\n",
dsDB.Tables[0].Rows.Count);
Console.WriteLine("Columns\n=======\n");
foreach(DataColumn dcDB in dsDB.Tables[0].Columns)
Console.WriteLine("{0} ({1})", dcDB.ColumnName, dcDB.DataType);
Console.WriteLine("\n");
Console.WriteLine("Data\n====\n");
for(int i=0;i to continue...");
Console.Read();
}
}
Freddy Perez Computacion y Sistemas freperez98@gmail.com Aragua Venezuela
No hay comentarios:
Publicar un comentario