1 / 5

ここが知りたい ! ADO.NET 接続型アーキテクチャ

ここが知りたい ! ADO.NET 接続型アーキテクチャ. ADO.NET とは ?. ADO.NET とは ? .NET Framework で提供されるデータアクセスのためのクラスライブラリ 汎用プログラミングインターフェイス 実装形態の選択肢. 接続型 データ操作中は接続を維持. クライアント. データベース サーバー. 接続. DataSet. 非接続型 データ操作中は接続を一旦切断. データ層. 接続型のオブジェクト モデル. Connection データソースへの接続 Command コマンドの実行 DataReader

Download Presentation

ここが知りたい ! ADO.NET 接続型アーキテクチャ

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ここが知りたい! ADO.NET 接続型アーキテクチャ

  2. ADO.NET とは ? • ADO.NET とは? • .NET Framework で提供されるデータアクセスのためのクラスライブラリ • 汎用プログラミングインターフェイス • 実装形態の選択肢 接続型 データ操作中は接続を維持 クライアント データベース サーバー 接続 DataSet 非接続型 データ操作中は接続を一旦切断 データ層

  3. 接続型のオブジェクト モデル • Connection • データソースへの接続 • Command • コマンドの実行 • DataReader • 接続型レコードセット • Forward only / Read only クライアント 接続型 データソース DataReader Command Connection

  4. 接続型によるデータ参照 • Connection/Command を直接使用 • ExecuteReader メソッドでDataReader にデータを格納 C# static void Main(string[] args) { OleDbConnection cn = new OleDbConnection(); OleDbCommand cmd = new OleDbCommand(); OleDbDataReader dr; cn.ConnectionString = strCn; //接続文字列 cn.Open(); cmd.Connection = cn; cmd.CommandText = "SELECT 商品名,単価 FROM Production.商品"; dr = cmd.ExecuteReader(); while( dr.Read() ) { s = dr.GetString(0); s = (string) dr["商品名"]; } dr.Close(); cn.Close(); }

  5. 接続型による更新 • Connection/Command を直接使用 • ExecuteNonQuery メソッドで変更処理を実行 C# static void Main(string[] args) { OleDbConnection cn = new OleDbConnection(); OleDbCommand cmd = new OleDbCommand(); cn.ConnectionString = strCn; //接続文字列 cn.Open(); cmd.Connection = cn; cmd.CommandText = "UPDATE Production.商品 SET 単価 = 単価 + 10 " + "WHERE 商品コード = 18"; //SQL文の実行 cmd.ExecuteNonQuery(); cn.Close(); }

More Related