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

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

 2007-05-13 12:30:03 来源:WEB开发网   
核心提示: // create the connectionOracleConnection conn = new OracleConnection("Data Source=oracledb;User Id=UserID;Password=Password;");// creat
// create the connection
OracleConnection conn = new OracleConnection("Data Source=oracledb;
  User Id=UserID;Password=Password;");
// create the command for the stored procedure
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "ADD_LOCATION";
cmd.CommandType = CommandType.StoredProcedure;
// add the parameters for the stored procedure including the LOCATION_ID
// sequence value that is returned in the output parameter p_location_id
cmd.Parameters.Add("p_location_id", OracleType.Number).Direction =
  ParameterDirection.Output;
cmd.Parameters.Add("p_street_address", OracleType.VarChar).Value =
  "123 Any Street";
cmd.Parameters.Add("p_postal_code", OracleType.VarChar).Value = "33040";
cmd.Parameters.Add("p_city", OracleType.VarChar).Value = "Key West";
cmd.Parameters.Add("p_state_province", OracleType.VarChar).Value = "FL";
cmd.Parameters.Add("p_country_id", OracleType.VarChar).Value = "US";
// execute the command to add the records  
OracleString rowId;
conn.Open();
int rowsAffected = cmd.ExecuteOracleNonQuery(out rowId);
conn.Close();
// output the results
Console.WriteLine("Rows affected: " + rowsAffected);
Console.WriteLine("Location ID: " +
  cmd.Parameters["p_location_id"].Value);

控制台显示一个记录被插入到该表中,同时还插入了该序列生成的主键值。

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

Tags:使用 ADO NET

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接