开发用于与数据库进行交互的界面
开发具有以下功能的 NetLogic:将值插入数据库、查询数据库并显示查询结果。
小贴士:
可从以下位置下载示例项目:
InteractWithDatabase.zip先决条件
创建项目。
- 选择运行
- 通过添加更多界面元素以及Insert、Update、Delete和Select方法来展开项目。[ExportMethod] public void Insert(int value) { var values = new object[1,2]; values[0,0] = DateTime.Now; values[0,1] = value; myTable.Insert(dbColumns, values); Log.Info("Insert","Inserted value: " + value.ToString()); } [ExportMethod] public void Update(int value, DateTime timestamp) { Object[,] ResultSet; String[] Header; myStore.Query("UPDATE Demo SET Value = " + value + " WHERE Timestamp = \"" + timestamp.ToString("o", CultureInfo.InvariantCulture) + "\"" , out Header, out ResultSet); Log.Info("Update", "Updated last record"); } [ExportMethod] public void Delete(int value) { Object[,] ResultSet; String[] Header; myStore.Query("DELETE FROM Demo WHERE Value<=65535 ORDER BY Timestamp DESC LIMIT 1", out Header, out ResultSet); Log.Info("Delete", "Deleted last record"); } [ExportMethod] public void Select(out int value) { Object[,] ResultSet; String[] Header; myStore.Query("SELECT * FROM Demo ORDER BY Timestamp DESC LIMIT 1", out Header, out ResultSet); value = Convert.ToInt32(ResultSet[0,1]); }可从以下位置下载示例项目:InteractWithDatabaseExpanded.zip
提供反馈