- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data.SqlClient;
- using System.Data;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- SqlCommand cmd = new SqlCommand();
- /*byte[] blob = new byte[16];
- byte[] blob0, blob1;
- double db0 = 7.5, db1 = 1.27;
- blob0 = BitConverter.GetBytes(db0);
- blob1 = BitConverter.GetBytes(db1);
- blob0.CopyTo(blob, 0);
- blob1.CopyTo(blob, 8);*/
- double db0, db1;
- byte[] blob0 = new byte[8];
- byte[] blob1 = new byte[8];
- using (SqlConnection conn = new SqlConnection("server=(local);database=database;uid=name;pwd=password"))
- {
- /*cmd.CommandType = System.Data.CommandType.Text;
- cmd.CommandText = "update WMETER_LOG set ExamData = @examdatas where DeviceCode = '5070386'";
- SqlParameter param = new SqlParameter("@examdatas", SqlDbType.Binary, blob.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, blob);
- cmd.Parameters.Add(param);
- cmd.Connection = conn;
- conn.Open();
- cmd.ExecuteNonQuery();*/
- cmd.CommandType = System.Data.CommandType.Text;
- cmd.CommandText = "select ExamData from WMETER_LOG where DeviceCode='5070386'";
- cmd.Connection = conn;
- conn.Open();
- SqlDataReader rdr = cmd.ExecuteReader();
- while (rdr.Read())
- {
- long val0 = rdr.GetBytes(0, 0, blob0, 0, 8);
- long val1 = rdr.GetBytes(0, 8, blob1, 0, 8);
- }
- }
- db0 = BitConverter.ToDouble(blob0, 0);
- db1 = BitConverter.ToDouble(blob1, 0);
- Console.Write(db1);
- Console.ReadLine();
- }
- }
- }
读写文件
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Runtime.Serialization;
- using System.IO;
- namespace FileTest
- {
- class Program
- {
- static void Main(string[] args)
- {
- double db;
- FileInfo myFile = new FileInfo(@"D:/lihongdian.msd");
- byte[] bt = new byte[8];
- /*db = 7.5;
- bt = BitConverter.GetBytes(db);
- FileStream fs = myFile.OpenWrite();
- fs.Write(bt, 0, 8);
- fs.Close();*/
- FileStream fs = myFile.OpenRead();
- fs.Read(bt, 0, 8);
- fs.Close();
- db = BitConverter.ToDouble(bt, 0);
- Console.Write(db);
- Console.ReadLine();
- }
- }
- }