现在的位置: 首页 > 综合 > 正文

Typed DataSet强类型Oracle的delete,update,insert

2017年10月02日 ⁄ 综合 ⁄ 共 1071字 ⁄ 字号 评论关闭

1.DELETE FROM "SALGRADE" WHERE id = :id

2.INSERT INTO "SALGRADE" ("GRADE",  "ID", "TEST") VALUES (:GRADE, :ID, :TEST)

3.UPDATE "SALGRADE" SET "GRADE" = :GRADE, "TEST"= :TEST where "ID" = :ID

具体实现代码:

先看一个半路失败的强类型

SALGRADETableAdapter adapter = new SALGRADETableAdapter();
            OrclDataSet.SALGRADEDataTable data = adapter.GetData();
            foreach (OrclDataSet.SALGRADERow r in data.Rows)//this is not typed dataset because the exist of the attribute :Rows
            {
                MessageBox.Show((r.HISAL).ToString());
                MessageBox.Show("aa");
            }

 

具体的使用:textBox1,是id(int),textBox2,是grade(int),textBox3是test(string)

主要代码

SALGRADETableAdapter adapter = new SALGRADETableAdapter();
            int id;
            int.TryParse(this.textBox1.Text, out id);
            int grade;
            int.TryParse(this.textBox2.Text, out grade);
            string test = this.textBox3.Text;
            //TestForm.OrclDataSet.SALGRADEDataTable table = adapter.GetData();
            //for (int i = 0; i < table.Count;i++ )
            //{
            //    if (table[i].ID == id)
            //    {
            //        table[i].GRADE = grade;
            //        table[i].TEST = test;
            //    }
            //}
            //adapter.Update(table);
            adapter.UpdateQuery(grade, test, id);


  lock (adapter)
            {
                adapter.InsertQuery(9999, 23, "another");
            }

int id;
            int.TryParse(this.textBox1.Text, out id);
            lock (adapter)
            {
                adapter.DeleteQuery(id);
            }

 

抱歉!评论已关闭.