using System; using System.Data; using StatusWare.Database;
namespace Teste { /// <summary> /// The classname must be the same as the table /// </summary> public class Teste : Table { [TableField(IsPrimaryKey = true, IsAutoIncrement = true)] private int idTeste;
[TableField] private double valorDouble;
[TableField] private decimal valorDecimal;
[TableField(Length = 60)] private string valorString;
[TableField] private string valorText;
[TableField] private DateTime datahora;
[TableField(Type = DbType.Date)] private DateTime data;
[TableField(Type = DbType.Time)] private DateTime hora;
[TableField(IsEncoded = true, EncodeString = "c4r4lh0")] private string coded;
public int IdTeste { get { return idTeste; } set { idTeste = value; } }
public double ValorDouble { get { return valorDouble; } set { valorDouble = value; } }
public decimal ValorDecimal { get { return valorDecimal; } set { valorDecimal = value; } }
public string ValorString { get { return valorString; } set { valorString = value; } }
public string ValorText { get { return valorText; } set { valorText = value; } }
public DateTime DataHora { get { return datahora; } set { datahora = value; } }
public DateTime Data { get { return data; } set { data = value; } }
public DateTime Hora { get { return hora; } set { hora = value; } }
public string Coded { get { return coded; } set { coded = value; } }
public Teste(Connection c) : base(c) { } }
/// <summary> /// Example for table Teste /// </summary> public class Program { static void Main(string[] args) { /* Table structure: * * CREATE TABLE Teste ( * idteste serial NOT NULL, * valordouble float8, * valordecimal numeric, * valorstring varchar(60), * valortext text, * datahora timestamp, * data date, * hora time, * coded varchar(20), * CONSTRAINT teste_pkey PRIMARY KEY (idteste) * ) */ Connection con = new Connection(SGBD.Postgresql);
if (!con.Connect("localhost", "username", "pass", "database", "Encoding=unicode")) throw new Exception("Não foi possível conectar ao banco de dados Postgresql");
Teste t = new Teste(con);
t.ValorText = "Testando"; t.ValorString = "çaslkf açsldfkaç"; t.ValorDouble = 22545.25; t.ValorDecimal = 12121.12M; t.DataHora = t.Hora = t.Data = DateTime.Now;
// inserting int rows = t.Insert(); int idTeste;
t.LoadGeneratedKey(); // getting the auto increment keys generated idTeste = t.IdTeste;
Console.WriteLine("Rows affected: {0} - Works: {1}", rows, rows > 0);
// updating t.ValorDouble = 2222222.22; rows = t.Update();
Console.WriteLine("Rows affected: {0} - Works: {1}", rows, rows > 0);
// loading t = new Teste(con); t.IdTeste = idTeste; t.Load();
Console.WriteLine(t);
// deleting t.Delete();
con.Close();
Console.Read(); } } }
| Program.cs | 3.2 K | 2005-05-04 |
© 2008 Novell, Inc. All Rights Reserved.