在使用的过程中,我使用了飞凌公司的7寸电阻屏,使用过程中发现在进入待机界面时,有出现条状花屏现象而不是黑屏。希望飞凌公司能尽快处理。
我做的数据采集传输仪,会采集大量的数据进行存储,计算。
如果要对大数据进行统一管理,使用数据库是最好的选择,所以我采用了sql server数据库进行统一管理数据,我采用了本地数据库,现在将我的操作代码分享给大家
using System;
using System.Linq;
using System.Collec
tions.Generic;
using System.Text;
using System.Data.SqlServerCe;
using System.Data;
using System.Diagnostics;
namespace scy.SqlServer
{
class CommonDB
{
SqlCeConnection Connection = new SqlCeConnection();
public SqlCeConnection DB_Open()
{
string constr = "Data Source=" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\MyscyDB.sdf;PassWord=sdyyhbscy;Persist Security Info=False";
// string constr = "Data Source=" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\MyscyDB.sdf;Persist Security Info=False";
SqlCeConnection Con = new SqlCeConnection(constr);
try
{
if (Connection.State == ConnectionState.Closed)
{
Con.Open();
Connection = Con;
Debug.WriteLine("数据库成功链接");
}
else
{
Debug.WriteLine("数据库已经打开");
}
}
catch
{
MySystem.WriteLog writelog = new MySystem.WriteLog();
writelog.MyWriteDRALog(@"数据库打开失败", "MyDB");
}
return Con;
}
//由Select语句和表名,获得对应的DataSet 数据集
public DataSet GetDataSet(string Sql, int startRecord,int maxRecords,string tablename)
{
SqlCeCommand Cmd = new SqlCeCommand(Sql, Connection);
SqlCeDataAdapter Sda = new SqlCeDataAdapter(Cmd);
DataSet Ds = new DataSet();
try
{
Sda.Fill(Ds, startRecord, maxRecords, tablename);
return Ds;
}
catch
{
MySystem.WriteLog writelog = new MySystem.WriteLog();
writelog.MyWriteDRALog(@"数据库数据读取错误", "MyDB");
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
}
}
return null;
}
//由Select语句和表名,获得对应的DataSet 数据集
public DataSet GetDataSet(string Sql)
{
SqlCeCommand Cmd = new SqlCeCommand(Sql, Connection);
SqlCeDataAdapter Sda = new SqlCeDataAdapter(Cmd);
DataSet Ds = new DataSet();
try
{
Sda.Fill(Ds);
return Ds;
}
catch
{
MySystem.WriteLog writelog = new MySystem.WriteLog();
writelog.MyWriteDRALog(@"数据库数据读取错误", "MyDB");
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
}
}
return null;
}
public int GetCountData(string Sql)
{
int count = 0;
SqlCeCommand Cmd = new SqlCeCommand(Sql, Connection);
try
{
count = Cmd.ExecuteNonQuery();
}
catch
{
MySystem.WriteLog writelog = new MySystem.WriteLog();
writelog.MyWriteDRALog(@"数据库数据查询数量错误", "MyDB");
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
}
}
return count;
}
public int update(string Sql, SqlCeParameter[] paras)
{
int count = 0;
SqlCeCommand Cmd = new SqlCeCommand(Sql, Connection);
foreach (SqlCeParameter p in paras)
{
Cmd.Parameters.Add(p);
}
try
{
count = Cmd.ExecuteNonQuery();
}
catch
{
MySystem.WriteLog writelog = new MySystem.WriteLog();
writelog.MyWriteDRALog(@"数据库数据更新错误", "MyDB");
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
}
}
return count;
}
public int SaveData(string Sql, SqlCeParameter[] paras,string name)
{
int count = 0;
SqlCeCommand Cmd = new SqlCeCommand(Sql, Connection);
foreach (SqlCeParameter p in paras)
{
Cmd.Parameters.Add(p);
}
try
{
count = Cmd.ExecuteNonQuery();
}
catch
{
MySystem.WriteLog writelog = new MySystem.WriteLog();
writelog.MyWriteDRALog(@"数据库"+ name +" "+ paras[0].Value + "存入错误", "MyDB");
}
return count;
}
public int DB_DataDelete(string str)
{
int counts = 0;
MySystem.WriteLog writelog = new MySystem.WriteLog();
try
{
DB_Open();
string sql = "delete " + str;
SqlCeCommand cmd = new SqlCeCommand(sql, Connection);
counts = cmd.ExecuteNonQuery();
Connection.Close();
writelog.MyWriteDRALog(@"数据库"+str+"删除"+counts+"条数据", "MyDB");
}
catch
{
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
writelog.MyWriteDRALog(@"数据库" + str + "删除历史数据错误", "MyDB");
}
}
return counts;
}
public int DB_DataDelete(string type, string time)
{
int counts = 0;
MySystem.WriteLog writelog = new MySystem.WriteLog();
try
{
DB_Open();
string sql = "delete from " + type + " where DataTime < '" + time + "'";
SqlCeCommand cmd = new SqlCeCommand(sql, Connection);
counts = cmd.ExecuteNonQuery();
Connection.Close();
writelog.MyWriteDRALog(@"数据库" + type + "删除" + counts + "条数据", "MyDB");
}
catch
{
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
writelog.MyWriteDRALog(@"数据库" + type + "删除历史数据错误", "MyDB");
}
}
return counts;
}
public void DB_Close()
{
if (Connection != null)
Connection.Close();
Debug.WriteLine("数据库成功关闭");
}
}
}