The only thing that I can find is Using, but this does not appear to work in the same way as With....
For example, in VB I can define which object I am working with and then not use the object name again - something like this....
With myObject
.Color = "Red"
.FontSize = "12"
End With
In the above example, I only have to type "myObject" once.
Is this also possible in C#?
Thanks
Gary
VulpesPosted Jun 24, 2011, 11:07 AM
Gary KingPosted Jun 24, 2011, 11:14 AM
Ok, not exactly what I was thinking of (along the lines of VB With / End With), but this will do.
Gary KingPosted Jun 24, 2011, 10:44 AM
Here is the code that I currently have - there are in fact 12 parameters needed for the Stored Proc:
SqlCommand cmdPermitHeader_INSERT = new SqlCommand("p_PermitHeader_INSERT", dbConnPermit);
cmdPermitHeader_INSERT.CommandType = CommandType.StoredProcedure;
cmdPermitHeader_INSERT.Parameters.Add("@FirstName", SqlDbType.NVarChar).Value = FirstName.Text;
How would you change that so that I could use:
p.Add("@FirstName", SqlDbType.NVarChar).Value = FirstName.Text;
VulpesPosted Jun 24, 2011, 9:54 AM
var myObject = new SomeType(someArg) { Color = "Red", FontSize = "12" };
Gary KingPosted Jun 24, 2011, 9:33 AM
The object in question is a SqlCommand of type StroedProcedure.
What I wanted to do is add all the SP Parameters without having to type the object name for each parameter.
Oh well!!!
VulpesPosted Jun 24, 2011, 8:52 AM