This code snippet for listing all the files under specific folder.
string[] list = Directory.GetFiles(Server.MapPath("~/Images"));
for (int i = 0; i < files.Length; i++){
list [i] = Path.GetFileName(list [i]);
GridView1.DataSource = list;
GridView1.DataBind(); }
Thursday, September 24, 2009
Saturday, August 22, 2009
Returning multiple refcursor in Oracle through enterprise library 4.1
I found this simple code snippet for how to retrieve multiple RefCursor values in Oracle through Enterprise Library 4.1
object[] parameters = new object[3];
DataSet ds = new DataSet();
Database db = DatabaseFactory.CreateDatabase();
DBCommandWrapper cw = db.GetStoredProcCommandWrapper("mypackage.mypackagename", parameters);
db.LoadDataSet(cw, ds, new string[] {"RefCur1", "RefCur2", "RefCur3"});
object[] parameters = new object[3];
DataSet ds = new DataSet();
Database db = DatabaseFactory.CreateDatabase();
DBCommandWrapper cw = db.GetStoredProcCommandWrapper("mypackage.mypackagename", parameters);
db.LoadDataSet(cw, ds, new string[] {"RefCur1", "RefCur2", "RefCur3"});
Thursday, August 20, 2009
Exception handling in Enterpirse Library 4.1
After goggling lot very patiently,I find something all irrelevant to my task.
Finally i corrected by watching carefully on my system thrown exceptions.
Add this below line between ConfigSection of tag.
section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" /
Paste this line somewhere but between configuration tag
exceptionHandling
exceptionPolicies
add name="Global Policy"
exceptionTypes
add name="Exception"
type="System.Exception,
mscorlib, Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=b77a5c561934e089"
postHandlingAction="None"
/add
/exceptionTypes
/add
/exceptionPolicies
/exceptionHandling
My source code for catching the exception is
try
{
int a = 0;
int b = 1;
int result = b / a;
Response.Write(result.ToString());
}
catch (System.Exception ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, "Global Policy");
Response.Write(rethrow.ToString());
}
Output is "False".So I am strongly believe exceptions were caught by enterprise library : )-
Finally i corrected by watching carefully on my system thrown exceptions.
Add this below line between ConfigSection of tag.
section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" /
Paste this line somewhere but between configuration tag
exceptionHandling
exceptionPolicies
add name="Global Policy"
exceptionTypes
add name="Exception"
type="System.Exception,
mscorlib, Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=b77a5c561934e089"
postHandlingAction="None"
/add
/exceptionTypes
/add
/exceptionPolicies
/exceptionHandling
My source code for catching the exception is
try
{
int a = 0;
int b = 1;
int result = b / a;
Response.Write(result.ToString());
}
catch (System.Exception ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, "Global Policy");
Response.Write(rethrow.ToString());
}
Output is "False".So I am strongly believe exceptions were caught by enterprise library : )-
Monday, August 17, 2009
Record retreiving C# using OracleProcedure
Oracle Proc:
create or replace procedure returnAllRecords(cur_allrec out t_cursor)
is
begin
open cur_allrec for SELECT * from Students;
end returnAllRecords
on Button click event write this below code:
OracleConnection Conn = new OracleConnection("Data Source=ORCL; User ID=scott; Password=tiger")
OracleCommand Cmd = new OracleCommand();
Cmd.Connection = Conn;
Cmd.CommandText = "returnAllRecords";
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.Parameters.Add("cur_allrec", OracleType.Cursor).Direction = ParameterDirection.Output;
try
{
Conn.Open();
OracleDataReader Reader = Cmd.ExecuteReader();
}
catch (Exception ex)
{
Response.Write(ex.ToString();
}
Conn.Close();
create or replace procedure returnAllRecords(cur_allrec out t_cursor)
is
begin
open cur_allrec for SELECT * from Students;
end returnAllRecords
on Button click event write this below code:
OracleConnection Conn = new OracleConnection("Data Source=ORCL; User ID=scott; Password=tiger")
OracleCommand Cmd = new OracleCommand();
Cmd.Connection = Conn;
Cmd.CommandText = "returnAllRecords";
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.Parameters.Add("cur_allrec", OracleType.Cursor).Direction = ParameterDirection.Output;
try
{
Conn.Open();
OracleDataReader Reader = Cmd.ExecuteReader();
}
catch (Exception ex)
{
Response.Write(ex.ToString();
}
Conn.Close();
Subscribe to:
Posts (Atom)