|
delphidab wrote:
C# is *very* picky about them trailing Open and Close parens isn't it? '()'.
It's the same in C(++) and Java. All methods need parentheses regardless of whether they return something or not (void ).
But properties don't need parentheses.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Yeah, well... This is my first exposure to C#. It's been almost 9 years since my last exposure to C/C++. And I've never worked with Java. I'm coming from Delphi. In Delphi, you didn't need to put in the parens if the procedure or function didn't expect arguments.
Derek
|
|
|
|
|
I'm not usually one to complain, but I'd like to say publicly that I despise writing SQL statements using C# strings. In fact, the whole ADO.NET model really stinks, very tedious and hugely error-prone.
I mean, calling a simple stored procedure with a few arguments is a royal pain:
SqlConnection connection = new SqlConnection(...);
string commandText = "MyStoredProcName";
SqlCommand command = new SqlCommand(commandText, connection);
SqlParameter param = new SqlParameter("@param1", [database type], [data type size], [source column]...);
param.Value = 5;
SqlParameter param2= new SqlParameter("@param2", ...);
param2.Value = someGuid;
command.Parameters.Add(new SqlParameter[]
{
param1,
param2
});
try
{
connection.Open();
object returnValue = command.ExecuteScalar();
return (int)returnValue;
}
catch(SqlException)
{
...
}
All this for calling a single stored procedure! And refactoring -- refactoring is tedious because all the code is strings. Error prone, and no way to catch it at compile time.
So I was hoping one of you might know of some tool that either generates code like this automatically, and/or checks for the validity of code against a stored procedure. Is there anything like this?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
Judah Himango wrote: // I sure hope the database guy doesn't change the stored proc name, or I'll be screwed!
Judah Himango wrote: // I sure hope the database guy doesn't change this stored proc parameter, or I'll be screwed!
Judah Himango wrote: // I sure hope the DBA doesn't modify the return type, or I'm screwed!
It sounds like the problem is more to do with team communication rather than ADO.NET. Would you like to suggest a way of working where your code would not be screwed by someone changing the stored procedure name, the parameters or the return type?
Judah Himango wrote: // Oh, great, boxing! Thanks ADO.NET!
How would you suggest it is done? Given the roundtrip time of calling a stored procedure on a database the additional time it takes to box this value is negligable. When running a SQL Command you have much greater performance problems to worry about than that piddling little thing.
Judah Himango wrote: All this for calling a single stored procedure! And refactoring -- refactoring is tedious because all the code is strings.
I write a DAO (Data Access Object) class to wrap this up neatly. Most of my public methods are just one or two lines long. All the rest is common enough to be sent to private methods to be called from the public one.
I've also experimented with using reflection to work out what should be built as I use a cradle-to-grave naming convention and my DAO class acts as a proxy to the stored procedures, so its public interface is basically a C# representation of the stored procedures.
Judah Himango wrote: So I was hoping one of you might know of some tool that either generates code like this automatically, and/or checks for the validity of code against a stored procedure.
I've not yet found a code gen tool that solved more problems than it created.
ColinMackay.net
Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
|
|
|
|
|
Colin Angus Mackay wrote: Would you like to suggest a way of working where your code would not be screwed by someone changing the stored procedure name, the parameters or the return type?
Sure: a tool that statically analyzes my code and the database code, making sure it's all synced and compatible. Or at very least, a tool that could generate ADO.NET code given a stored proc, view, etc. so that if major changes are made, it would just regenerate ADO.NET code to make it all work nicely again. My C# code would then fail at compile-time, rather than at run-time.
Colin Angus Mackay wrote: When running a SQL Command you have much greater performance problems to worry about than that piddling little thing.
Ha, that's true, but if you put this on a server where thousands of sprocs are being called, this contributes to more garbage collection, degrading performance. I would suggest a generic class for this; after all, most sproc parameters are value types (come to think of it, the only time I use reference types would be when dealing with text or binary data). I suppose some of the marshalling and casting to get this to work might offset the benefits, if it's at all technologically possible.
|
|
|
|
|
I'm working on a web based project that uses a Web Service to read from and write to an access database on the server.
I have compiled the service and it works with database, seemingly, fine when i switch anon' access to the web service OFF.
My problem is that switching off anon' access means my web app page can no longer talk to the web service
I know this is probably dead simple and a stupid oversite but im having no luck trying to resolve this.
I'm also petty green when it comes to all the web based permisions stuff.
The Web service wont alllow anon users (It wont work with the DB otherwise)
It accepts all users, authenticates in Windows mode and impersonates = true
The web app: accepts all users, authenticates in Windows mode and impersonates = true
Any help with this would be very welcome.
Thanks.
|
|
|
|
|
Hi,
How can I add arrows like the ones that appear in DAP or IDM. Which says "Show Details" and contains an arrow that points downwards and when you click on it, it changes to "Hide Details" and the arrow points upwards... I hope my question is clear
There is no patch for ignorance
|
|
|
|
|
The test way is to change the text of the button on the click event. This way you can toggle between the texts ">>Detail" to "Detail<<". The other way is to change the image on the button
this.buttonTest.Image = (Image)TestIcons.GetIcon("ShowDetails.ico").ToBitmap();
Live Life King Size
Alomgir Miah
|
|
|
|
|
Alomgir Miah wrote: this.buttonTest.Image = (Image)TestIcons.GetIcon("ShowDetails.ico").ToBitmap();
Is 'TestIcons' an ImageList??
There is no patch for ignorance
|
|
|
|
|
Can anybody help me how can i uninstall a software pesent in the remote system?.thanks in advance
|
|
|
|
|
private void func1()
{
TP=1000000;
start_volumn=new double[TP];
pre_volumn=new double[TP];
post_volumn=new double[TP];
best_end_volumn=new double[TP];
}
For some reason, I need call function func1 many times. what will happen to the gabage collection system of C#? at the second time to run start_volumn=new double[TP]; will the memory allocated by the first time running start_volumn=new double[TP] by released?
THX
|
|
|
|
|
The memory will be collected when the garbage collector lazily collects. You can force a collection via GC.Collect(), however this is not recommended in typical situations.
|
|
|
|
|
That depends on the scope of the references you use. If you don't have references the previous arrays, the memory will be garbage collected when needed.
You should remove the reference (e.g. setting it to null) as soon as you don't need any of the arrays.
If the references may still point to old arrays when you enter the method, you'd better release those before you allocate the new arrays:
start_volumn = null;<br />
pre_volumn = null;<br />
post_volumn = null;<br />
best_end_volumn = null;<br />
start_volumn = new double[TP];<br />
pre_volumn = new double[TP];<br />
post_volumn = new double[TP];<br />
best_end_volumn = new double[TP];
This way the memory will be available for garbage collection if needed. If you don't do this, the reference will not be released until the new array is allocated and the new reference replaces the old.
If possible, you should consider reusing the same arrays instead of allocating new ones over and over.
---
b { font-weight: normal; }
|
|
|
|
|
Guffa wrote: If you don't do this, the reference will not be released until the new array is allocated and the new reference replaces the old.
But it is still up to the garbage collector to take back the memory. In an array like this it will instantly go into the third-generation heap when it was created, and so wouldn't be collected for a while anyway.
Maybe I'm spoilt. I work on server systems most of the time (6+Gb of RAM) so I never really worry about these things because I know that once it goes out of scope, with no other references, the garbage collector will get it when it needs to.
ColinMackay.net
Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
|
|
|
|
|
Yes, but the memory can't be taken back as long as there is a reference to the array. Compare these two codes:
ref = new double[5000];<br />
ref = null;<br />
ref = new double[1000];
Without releasing the reference:
ref = new double[5000];<br />
ref = new double[1000];<br />
---
b { font-weight: normal; }
|
|
|
|
|
Hence my second paragraph about being spoilt working on server systems with gargantuan amounts of memory.
ColinMackay.net
Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
|
|
|
|
|
Hi
I have a decimal value which i want to convert to string but it drops off .0 (decimal)
I can't format since whatever value in decimal I want it as it is in string
ex. 88.99 88.00 88.0 or just 88
Thanks
Thanks
|
|
|
|
|
double val = 88.00;
string valStringWithZeroes = string.Format("{0:0.00}", val);
You can see a list of string formatting options from this blog posting[^].
|
|
|
|
|
This is great but doesn't work if i have 88.0 it will format that to 88.00
I want which shows # as it is ... like 88.0 or 88888.888
Thanks
|
|
|
|
|
Your problem is that
double val = 88.0;
Is the same value as
double val = 88.0000;
They're the same in the real mathematical sense of decimal values, as well as the same in the CLR. So, there's no way for you to print out whether it's 88.0 or 88.0000 if you're storing it as a double. I'm not sure whether there's a type in the CLR that stores an arbitrary number of decimal places as part of the value type itself.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
Judah Himango wrote: They're the same in the real mathematical sense of decimal values, as well as the same in the CLR. So, there's no way for you to print out whether it's 88.0 or 88.0000 if you're storing it as a double. I'm not sure whether there's a type in the CLR that stores an arbitrary number of decimal places as part of the value type itself.
For something not being modifed in code, String.
If you need to use it arithmatically, I'd suggest looking at scientific libraries for a class that handles significant figures, because with SF 88.1 != 88.10. The former represents the range 88.05
|
|
|
|
|
dan neely wrote: SF 88.1 != 88.10
I knew someone would call me out on this. It all depends on the context really; if we're talking about precision, yes, they are obviously not the same. If we're talking about simple arithmetic, they are the same value if precision is ignored (which is often the case in arithmetic). Anyways...for his uses, he'll need to either get a scientific library or write a type that preserves decimal precision, so it seems. I can't find any type in the CLR that preserves decimal precision.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
I know 88 is same as 88.0 or 88.00 but according to my requriments i have two #'s coming in ex 00.00 as string aand 88.00 as decimal .... now i have to compare string # to decimal which means that my number should have 2 digit before decimal and 2 digit after
another example one # is 0.0 measn another # should have one digit before decimal and one digit after decimal ... regardless of 8.0 is same as 8.00 or 8 ... in my case only 8.0 or 8.1 0r 8.2 or 9.1 are the valid digit since one digit after decimal and one digit before decimal
That's why i can't use formating since i don't what's the 1st # will look like which is string and what's the 2nd # looks like which is decimal
Thanks
|
|
|
|
|
Judah Himango wrote: dan neely wrote:
SF 88.1 != 88.10
I knew someone would call me out on this. It all depends on the context really; if we're talking about precision, yes, they are obviously not the same.
true. I mainly included it since I wasn't sure what the OP wanted, and wanted to epxlain why the class was doing what it was and check for potential side effects instead of assuming it was a 'double but keeps empty decimal places' and then getting burned over it enforcing SF, or the like.
|
|
|
|
|
The problem is that there is no single format that will achieve your goal
Say you have 88.0 and 88888.888
Console.WriteLine("{0 ##}", num)
will give you
88.0
88888.888
the problem is that if you have another number of finer precision, say 99.1234, it will be rounded to 99.124.
If you use the general format g
Console.WriteLine("{0:g}", num)
then you will get
88
88888.888
99.1234
If you have a hard need to display 88 as 88.0 then you will probably need to use two format strings
Dim nums() As Double = {88, 88888.888}
Dim numFmt As String
For Each num As Double In nums
Dim tmpNum As Double = System.Math.Abs(num)
If (System.Math.Floor(tmpNum) = tmpNum) Then
numFmt = "#.0"
Else
numFmt = "g"
End If
Dim exprFmt As String = "{0:" & numFmt & "}"
Console.WriteLine(exprFmt)
Console.WriteLine(String.Format(exprFmt, num))
Next
End Sub
NOTE: When testing this, it works well for Doubles but not singles. Don't know why
hth,
Alan.
if (
|
|
|
|