//按照方式一插入数据 public ErrorNum.Error InsertEPC1(string[] EPC) { try { tables = SQLDatabBase.GetTables(); bool exist = false; foreach (string tablename in tables) //表的名字和设备号对应则写入 否则创建新的表格 { if (tablename == EPC[0]) { db.InsertSingleData(tablename, EPC); exist = true; } } if (!exist) //创建新的表格 并写入数据 { string[] name = { "time", "devID", "types", "error", "antID", "EPC", "PC", "RSSI", "differentialtime", "direction", "intervaltime", "count", "ClientIP" }; string[] atttribute = { "Datetime", " Varchar(5)", " Varchar(12)", " Varchar(5)", " Varchar(6)", " Varchar(8)", " Varchar(8)", " Varchar(5)", " Varchar(16)" }; string[] isnull = { "not null", "not null", "not null", "not null", "not null", "not null", "not null", "not null", "not null", "not null" }; if (!db.CreatTables(EPC[0], db.SQLComamndFormat(name, atttribute, isnull))) { return(ErrorNum.Error.SQL_CREAT_TABLES_FAILED); } db.InsertSingleData(EPC[0], EPC); } return(ErrorNum.Error.SQL_OPER_SUCCESS); } catch (Exception ex) { ErrorLog.WriteError(ex.ToString()); throw ex; } }
public ErrorNum.Error InsertCommand(string[] Comamnd) { try { if (Comamnd.Length > MaxCommandLen) { return(ErrorNum.Error.SQL_INSERT_LEN_TOOLONG); } else { string[] insubffcient = new string[MaxCommandLen]; Comamnd.CopyTo(insubffcient, 0); bool exist = false; tables = SQLDatabBase.GetTables(); foreach (string tablename in tables) //表的名字和设备号对应则写入 否则创建新的表格 { if (tablename == readercommand) { db.InsertSingleData(tablename, insubffcient); exist = true; } } if (!exist) //创建新的表格 并写入数据 { string[] name = { "time", "devID", "types", "error", "value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9", "value10", "value11", "value12", "value13", "value14", "value15", "value16", "value17", "value18", "value19", "value20", "value21", "value22", "value23", "value24", "value25" }; string[] atttribute = { "Datetime", " Varchar(9)", " Varchar(3)", " Varchar(3)", " Varchar(100)", " Varchar(100)", " Varchar(100)", " Varchar(100)", " Varchar(100)", " Varchar(100)" , " Varchar(100)", " Varchar(100)", " Varchar(100)", " Varchar(100)", " Varchar(100)", " Varchar(100)", " Varchar(100)", " Varchar(100)", " Varchar(100)" , " Varchar(100)", " Varchar(100)", " Varchar(100)", " Varchar(100)", " Varchar(100)", " Varchar(100)", " Varchar(100)", " Varchar(100)", " Varchar(100)" , " Varchar(100)" }; string[] isnull = { "not null", "not null", "not null", "not null", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", }; if (!db.CreatTables(readercommand, db.SQLComamndFormat(name, atttribute, isnull))) { return(ErrorNum.Error.SQL_CREAT_TABLES_FAILED); } db.InsertSingleData(readercommand, insubffcient); } return(ErrorNum.Error.SQL_OPER_SUCCESS); } } catch (Exception ex) { ErrorLog.WriteError(ex.ToString()); throw ex; } }
/* public DataTable GetMaxTimeStamp() * { * * string cmd = string.Format("select * from {0} where time >='{1}' and time<='{2}' and antID = '{3}' order by time", tablename, startTime, endTime, ant); * return SQLDatabBase.SelectValuebyCondition(cmd, tablename); * }*/ //依据时间查询 public DataTable SelectByMultiContion(string startTime, string endTime, string tablename) { string cmd = string.Format("select * from {0} where time >='{1}' and time<='{2}' order by time", tablename, startTime, endTime); return(SQLDatabBase.SelectValuebyCondition(cmd, tablename)); }
//按照时间段来查询 public DataTable Selectbytime(string startTime, string endTime, string tablename) { string cmd = string.Format("select * from Sales where time >='{0} and time<='{1}", startTime, endTime); return(SQLDatabBase.SelectValuebyCondition(cmd, tablename)); }