使用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);
使用多个结果集
[]
- ››使用脚本恢复WinXP系统的用户登录密码
- ››使用phpMyadmin创建数据库及独立数据库帐号
- ››使用Zend Framework框架中的Zend_Mail模块发送邮件...
- ››使用cout标准输出如何控制小数点后位数
- ››使用nofollow标签做SEO的技巧
- ››使用 WebSphere Message Broker 的 WebSphere Tra...
- ››使用SQL Server事件探查器做应用程序的性能分析
- ››使用SQL Server事件探查器分析死锁原因
- ››Adobe发布Acrobat X 不支持苹果iOS系统
- ››使用纯文本文件打造WCF服务
- ››使用 Dojo 开发定制 Business Space 小部件,第 4...
- ››使用 ADDRESS 与 INDIRECT函数查询信息
更多精彩
赞助商链接