Dynamic Support
Visual C# 2010 provides support for late binding to dynamic types by introducing a new type, dynamic. This addition enables many new scenarios, including simplified access to COM APIs such as the Office Automation APIs, to dynamic APIs such as IronPython libraries, and to the HTML Document Object Model (DOM).
Office Programmability
Access to COM interfaces, including the Office Automation APIs, is greatly enhanced by the addition of named and optional arguments, the dynamic type, indexed properties and optional ref modifiers.
Type Equivalence Support
You can now deploy an application that has embedded type information instead of type information that is imported from a Primary Interop Assembly (PIA). With embedded type information, your application can use types in a runtime without requiring a reference to the runtime assembly. If various versions of the runtime assembly are published, the application that contains the embedded type information can work with the various versions without having to be recompiled.
Covariance and Contravariance
Covariance enables you to use a more derived type than that specified by the generic parameter, whereas contravariance enables you to use a less derived type. This allows for implicit conversion of classes that implement variant interfaces and provides more flexibility for matching method signatures with variant delegate types. Variant interfaces and delegates can be created by using the new in and out language keywords. The .NET Framework also introduces variance support for several existing generic interfaces and delegates, including the IEnumerable<(Of <(T>)>) interface and the Func<(Of <(TResult>)>) and Action<(Of <(T>)>) delegates.
New Command-Line Options
The /langversion command-line option causes the compiler to accept only syntax that is valid in the specified version of C#.
The /appconfig compiler option enables a C# application to specify the location of an assembly's application configuration file to the compiler.
Call Hierarchy
Call Hierarchy enables you to navigate through your code by displaying the following:
All calls to and from a selected method, property, or constructor
All implementations of an interface member
All overrides of a virtual or abstract member
This enables you to better understand how code flows and to evaluate the effects of changes to code.
Navigate To
You can use the Navigate To feature to search for a symbol or file in source code. You can search for keywords that are contained in a symbol by using Camel casing and underscore characters to divide the symbol into keywords.
Highlighting References
When you click a symbol in source code, all instances of that symbol are highlighted in the document. To move to the next or previous highlighted symbol, you can use CTRL+SHIFT+DOWN ARROW or CTRL+SHIFT+UP ARROW.
Generate From Usage
The Generate From Usage feature enables you to use classes and members before you define them. Without leaving your current location in code, you can generate a stub for a class, constructor, method, property, field, or enum that you want to use but have not yet defined. This minimizes interruption to your workflow.
Generate From Usage supports programming styles such as test-first development.
IntelliSense Suggestion Mode
IntelliSense now provides two alternatives for IntelliSense statement completion: completion mode and suggestion mode. Suggestion mode is used when classes and members are used before they are defined.
Live Semantic Errors
The Live Semantic Errors feature has been enhanced in Visual C# 2010. The use of wavy underlines to signal errors and warnings as you type has been extended to include constructs that are outside of method bodies, such as return types, parameter types, and default values in method declarations.
Thursday, March 25, 2010
Friday, March 19, 2010
Send collection to stored procedure
There are times when you want to insert more than one row to a table(s) through a stored procedure using .Net. This can be done using a for/while loop but that would make too many trips to the database. Best way is to send the parameters as a collection and the ODP client the do the rest for you. This will run all the insert queries at one go in a single Database trip and do a commit. It enhances a large amount of performance.
C# code:
public void InsertIntoDB(object response)
{
// Oracle objects
OracleConnection myConnection = null;
try
{
myConnection = OpenOracleConnection();
OracleCommand myCommand = GetInsertIntoDB(myConnection, response);
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{..}
finally
{
myConnection.Close();
myConnection = null;
}
}
public static OracleCommand GetInsertIntoDB(object response)
{
OracleCommand myCommand = myConn.CreateCommand();
myCommand.Connection = myConn;
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "insert";
string[] tranIds = new string[4];
int[] tranAmts = new int[4];
string[] tranNames = new string[4];
string[] tranAddress = new string[4];
for (int i = 0; i < 4; i++)
{
tranIds[i] = response[i].tranId;
tranAmts[i] = Convert.ToInt16(response[i].tranAmt);
tranNames[i] = response[i].tranName;
tranAddress[i] = response[i].tranAddres;
}
myCommand.Parameters.Add("p_tran_id", OracleDbType.Varchar2, tranIds, ParameterDirection.Input);
myCommand.Parameters.Add("p_tran_amt", OracleDbType.Int16, tranAmts, ParameterDirection.Input);
myCommand.Parameters.Add("p_tran_name", OracleDbType.Varchar2,tranNames, ParameterDirection.Input);
myCommand.Parameters.Add("p_tran_Addres", OracleDbType.Varchar2,tranAddress, ParameterDirection.Input);
myCommand.ArrayBindCount = tranIds.Length;
return myCommand;
}
Stored Procedure:
1. Inside Spec:
procedure insert(
p_tran_id in varchar2,
p_tran_amt in integer,
p_tran_name in varchar2,
p_tran_Addres in varchar2
);
2. Inside Body:
procedure insert(
p_tran_id in varchar2,
p_tran_amt in integer,
p_tran_name in varchar2,
p_tran_Addres in varchar2
)
AS
BEGIN
INSERT INTO TableName
(tran_id,
tran_amt,
tran_name,
tran_Addres
)
VALUES (p_tran_id,
p_tran_amt,
p_tran_name,
p_tran_Addres
);
COMMIT;
END insert;
C# code:
public void InsertIntoDB(object response)
{
// Oracle objects
OracleConnection myConnection = null;
try
{
myConnection = OpenOracleConnection();
OracleCommand myCommand = GetInsertIntoDB(myConnection, response);
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{..}
finally
{
myConnection.Close();
myConnection = null;
}
}
public static OracleCommand GetInsertIntoDB(object response)
{
OracleCommand myCommand = myConn.CreateCommand();
myCommand.Connection = myConn;
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "insert";
string[] tranIds = new string[4];
int[] tranAmts = new int[4];
string[] tranNames = new string[4];
string[] tranAddress = new string[4];
for (int i = 0; i < 4; i++)
{
tranIds[i] = response[i].tranId;
tranAmts[i] = Convert.ToInt16(response[i].tranAmt);
tranNames[i] = response[i].tranName;
tranAddress[i] = response[i].tranAddres;
}
myCommand.Parameters.Add("p_tran_id", OracleDbType.Varchar2, tranIds, ParameterDirection.Input);
myCommand.Parameters.Add("p_tran_amt", OracleDbType.Int16, tranAmts, ParameterDirection.Input);
myCommand.Parameters.Add("p_tran_name", OracleDbType.Varchar2,tranNames, ParameterDirection.Input);
myCommand.Parameters.Add("p_tran_Addres", OracleDbType.Varchar2,tranAddress, ParameterDirection.Input);
myCommand.ArrayBindCount = tranIds.Length;
return myCommand;
}
Stored Procedure:
1. Inside Spec:
procedure insert(
p_tran_id in varchar2,
p_tran_amt in integer,
p_tran_name in varchar2,
p_tran_Addres in varchar2
);
2. Inside Body:
procedure insert(
p_tran_id in varchar2,
p_tran_amt in integer,
p_tran_name in varchar2,
p_tran_Addres in varchar2
)
AS
BEGIN
INSERT INTO TableName
(tran_id,
tran_amt,
tran_name,
tran_Addres
)
VALUES (p_tran_id,
p_tran_amt,
p_tran_name,
p_tran_Addres
);
COMMIT;
END insert;
Subscribe to:
Comments (Atom)