插入、更新、删除
通过 DmCommand 对象的 ExecuteNonQuery 方法可以执行 INSERT 语句来插入数据,
C#示例代码如下:
using System; using System.Collections.Generic; using System.Text; using Dm; namespace DMDemo { class InsertDemo { //返回结果 static int ret = 1; static DmConnection cnn = new DmConnection(); [STAThread] static int Main(string[] args) { try { cnn.ConnectionString = "Server=localhost; User Id=SYSDBA; PWD=SYSDBA"; cnn.Open(); InsertDemo demo = new InsertDemo(); demo.TestFunc(); cnn.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); return ret; } public void TestFunc() { DmCommand command = new DmCommand(); command.Connection = cnn; try { command.CommandText = "INSERT INTO PRODUCTION.PRODUCT(NAME, AUTHOR, PUBLISHER, " + "PUBLISHTIME, PRODUCT_SUBCATEGORYID, PRODUCTNO, SATETYSTOCKLEVEL, ORIGINALPRICE, " + "NOWPRICE, DISCOUNT, DESCRIPTION, TYPE, PAPERTOTAL, WORDTOTAL, SELLSTARTTIME, " + "SELLENDTIME) VALUES ('三国演义', '罗贯中', '中华书局', '2005-04-01', 4, '9787101046121', " + "10, 19.0000, 15.2000, 8.0, '《三国演义》是中国第一部长篇章回体小说,中国小说" + "由短篇发展至长篇的原因与说书有关。宋代讲故事的风气盛行,说书成为一种职业,说" + "书人喜欢拿古代人物的故事作为题材来敷演,而陈寿《三国志》里面的人物众多,事件" + "纷繁,正是撰写故事的最好素材。三国故事某些零星片段原来在民间也已流传,加上说" + "书人长期取材,内容越来越丰富,人物形象越来越饱满,最后由许多独立的故事逐渐组" + "合而成长篇巨著。这些各自孤立的故事在社会上经过漫长时间口耳相传,最后得以加工" + "、集合成书,成为中国第一部长篇章回体小说,这是一种了不起的集体创造,与由单一" + "作者撰写完成的小说在形态上有所不同。', '16', 943, 93000, '2006-03-20', '1900-01-01')"; command.ExecuteNonQuery(); string a, b, c; command.CommandText = "SELECT NAME, AUTHOR, PUBLISHER FROM PRODUCTION.PRODUCT;"; DmDataReader reader = command.ExecuteReader(); while (reader.Read()) { a = reader.GetString(0); b = reader.GetString(1); c = reader.GetString(2); Console.WriteLine("NAME:" + a); Console.WriteLine("AUTHOR:" + b); Console.WriteLine("PUBLISHER:" + c); Console.WriteLine("-------------------"); } } catch (Exception ex) { Console.WriteLine(ex.Message); ret = 0; } } } } 通过 DmCommand 对象的 ExecuteNonQuery 方法可以执行 UPDATE 语句来更新数据, C#示例代码如下: command.CommandText = "UPDATE PRODUCTION.PRODUCT SET " + " NAME = '三国演义(上)' WHERE PRODUCTID = 11"; command.ExecuteNonQuery(); 通过 DmCommand 对象的 ExecuteNonQuery 方法可以执行 DELETE 语句来删除数据, C#示例代码如下: command.CommandText = "DELETE FROM PRODUCTION.PRODUCT WHERE PRODUCTID = 11"; command.ExecuteNonQuery();
https://xpanx.com/
评论