开发学院数据库Oracle 使用ADO.NET访问Oracle 9i存储过程(下) 阅读

使用ADO.NET访问Oracle 9i存储过程(下)

 2007-05-13 12:30:03 来源:WEB开发网   
核心提示: // define the connection stringString connString = "Data Source=oracledb;User Id=UserID;Password=Password;";// create the data adapterO
// define the connection string
String connString = "Data Source=oracledb;User Id=UserID;Password=Password;";
// create the data adapter
OracleDataAdapter da = new OracleDataAdapter();
// define the select command for the data adapter
OracleCommand selectCommand =
  new OracleCommand("CRUD_LOCATIONS.GetLocations",
  new OracleConnection(connString));
selectCommand.CommandType = CommandType.StoredProcedure;
selectCommand.Parameters.Add("cur_Locations",
  OracleType.Cursor).Direction = ParameterDirection.Output;
da.SelectCommand = selectCommand;
// define the udpate command for the data adapter
OracleCommand updateCommand =
  new OracleCommand("CRUD_LOCATIONS.UpdateLocations",
  new OracleConnection(connString));
updateCommand.CommandType = CommandType.StoredProcedure;
updateCommand.Parameters.Add("p_location_id", OracleType.Number, 4,
  "LOCATION_ID");
updateCommand.Parameters.Add("p_street_address", OracleType.VarChar, 40,
  "STREET_ADDRESS");
updateCommand.Parameters.Add("p_postal_code", OracleType.VarChar, 12,
  "POSTAL_CODE");
updateCommand.Parameters.Add("p_city", OracleType.VarChar, 30, "CITY");
updateCommand.Parameters.Add("p_state_province", OracleType.VarChar, 25,
  "STATE_PROVINCE");
updateCommand.Parameters.Add("p_country_id", OracleType.Char, 2,
  "COUNTRY_ID");
da.UpdateCommand = updateCommand;
// define the delete command for the data adapter
OracleCommand deleteCommand =
  new OracleCommand("CRUD_LOCATIONS.DeleteLocations",
  new OracleConnection(connString));
deleteCommand.CommandType = CommandType.StoredProcedure;
deleteCommand.Parameters.Add("p_location_id", OracleType.Number, 4,
  "LOCATION_ID");
da.DeleteCommand = deleteCommand;
OracleCommand insertCommand =
  new OracleCommand("CRUD_LOCATIONS.InsertLocations",
  new OracleConnection(connString));
insertCommand.CommandType = CommandType.StoredProcedure;
insertCommand.Parameters.Add("p_location_id", OracleType.Number, 4,
  "LOCATION_ID");
insertCommand.Parameters.Add("p_street_address", OracleType.VarChar, 40,
  "STREET_ADDRESS");
insertCommand.Parameters.Add("p_postal_code", OracleType.VarChar, 12,
  "POSTAL_CODE");
insertCommand.Parameters.Add("p_city", OracleType.VarChar, 30, "CITY");
insertCommand.Parameters.Add("p_state_province", OracleType.VarChar, 25,
  "STATE_PROVINCE");
insertCommand.Parameters.Add("p_country_id", OracleType.Char, 2,
  "COUNTRY_ID");
da.InsertCommand = insertCommand;
// define a DataTable and fill it using the data adapter
DataTable dt = new DataTable();
da.Fill(dt);
// ... do work that adds, edits, updates, or deletes records in the table
// call the Update() method of the data adapter to update the Oracle
// database with changes made to the data
da.Update(dt);

使用多个结果集

上一页  1 2 3 4 5 6 7  下一页

Tags:使用 ADO NET

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接