1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
static void Main(string[] args)
{
using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection())
{
conn.ConnectionString = "server=localJ;uid=sa;pwd=pass123;database=dbTest";
conn.Open();
using (System.Data.SqlClient.SqlCommand command = conn.CreateCommand())
{
command.CommandText = @"SELECT data,name, byte1 as r0, byte2 as r1
from hextb";
System.Data.SqlClient.SqlDataReader reader = command.ExecuteReader();
Datacolumn[] columns = new Datacolumn[]
{
new Datacolumn("id", System.Data.SqlDbType.Int),
new Datacolumn("code", System.Data.SqlDbType.Char,10),
new Datacolumn("name", System.Data.SqlDbType.VarChar),
new Datacolumn("date", System.Data.SqlDbType.DateTime),
new Datacolumn("memo", System.Data.SqlDbType.VarChar)
};
while (reader.Read())
{
byte[] data = (byte[])reader["r0"];
try
{
TranslateData(data, columns);
Console.WriteLine("Table : {1}, Données : {0}", reader["data"], reader["name"]);
foreach (Datacolumn c in columns)
{
Console.WriteLine("{0} = {1}", c.Name, c.Value);
}
Console.WriteLine();
}
catch
{
//to-do...
}
}
reader.Close();
}
conn.Close();
}
Console.WriteLine("************************");
Console.ReadLine();
}
public class Datacolumn
{
public string Name;
public System.Data.SqlDbType DataType;
public short Length = -1;
public object Value = null;
public Datacolumn(string name, System.Data.SqlDbType type)
{
Name = name;
DataType = type;
}
public Datacolumn(string name, System.Data.SqlDbType type, short length)
{
Name = name;
DataType = type;
Length = length;
}
} |
Partager