Eksempel:
using System;
using System.Data.Hsqldb.Client;
using System.Data.Hsqldb.Common.Enumeration;
namespace E
{
public class Program
{
public static void Main(string[] args)
{
HsqlConnection con = new HsqlConnection("jdbc:hsqldb:file:/temp/test;shutdown=true");
con.Open();
HsqlCommand cre = new HsqlCommand(con, "CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 VARCHAR(50))");
cre.ExecuteNonQuery();
HsqlCommand ins = new HsqlCommand(con, "INSERT INTO t1 VALUES(@f1,@f2)");
ins.Parameters.Add(new HsqlParameter("@f1", HsqlProviderType.Integer));
ins.Parameters.Add(new HsqlParameter("@f2", HsqlProviderType.VarChar, 50));
ins.Parameters["@f1"].Value = 1;
ins.Parameters["@f2"].Value = "A";
ins.ExecuteNonQuery();
ins.Parameters["@f1"].Value = 2;
ins.Parameters["@f2"].Value = "BB";
ins.ExecuteNonQuery();
ins.Parameters["@f1"].Value = 3;
ins.Parameters["@f2"].Value = "CCC";
ins.ExecuteNonQuery();
HsqlCommand sel = new HsqlCommand(con, "SELECT f1,f2 FROM t1");
HsqlDataReader rdr = sel.ExecuteReader();
while(rdr.Read())
{
int f1 = (int)rdr["f1"];
string f2 = (string)rdr["f2"];
Console.WriteLine(f1 + " " + f2);
}
rdr.Close();
HsqlCommand drp = new HsqlCommand(con, "DROP TABLE t1");
drp.ExecuteNonQuery();
con.Close();
Console.ReadKey();
}
}
}
♠