|
I dont see why becuase the name has to match the store procedure parameters but
SqlParameter sqlPar;
foreach sqlPar in mySqlCommand.Parameters
{
Debug.WriteLine(sqlPar.ParameterName);
}
|
|
|
|
|
I'd try same your code Ista, but it didn't work
thanks Einbu with your idea 
|
|
|
|
|
foreach( SqlParameter p in sqlGet.Parameters)
{
Debug.WriteLine("The name is " + p.ParameterName);
}
Well obviously from the compiler kick backs it says it must be declared and have a parentheses. so if you modify my code it works just fine.
I even included another code snippet for you:
Debug.WriteLine("The name is " + sqlGet.Parameters[0].ParameterName );
Sorry about the misprint but I havent been using the foreach a whole bunch
|
|
|
|
|
Is there any way to have the font color set by a rule? For example if the value in a cell is negative I would like it to be displayed as red. (It would be cool to set this rule on the column.) Can this be done?
|
|
|
|
|
|
Thanks Mazy!
I needed to change the fore color.
I used your idea and changed it to this
protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight)
{
Decimal val = (Decimal) GetColumnValueAtRow(source, rowNum);
if(val>0)
foreBrush = Brushes.Green;
else
foreBrush = Brushes.Red;
base.Paint (g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
}
Works well. Thanks again.
|
|
|
|
|
Ok, I am kinda stuck here, say I have class A which is instantiated on my main form, this class contains all a slew of properties and methods. I have a second form pop up and I want to transfer that class instance that is created on my main form over to the second form. The idea would allow me to pass the one instance all throughout the application regardless of the form it is on. My first thought was to create a property for the class, but I wasn't sure and I wanted to asking everyone else what they think is the best implementation here? Thanks in advance.
-Nick Parker
|
|
|
|
|
By class, I assume you mean control, right?
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Nope, just a regular class, it deals with a lot of XML processing.
-Nick Parker
|
|
|
|
|
Nick Parker wrote:
The idea would allow me to pass the one instance all throughout the application regardless of the form it is on.
If you will only have that one instance through-out the entire life of the application, then you would probably benefit from using a singleton.
public sealed class A
{
private A()
{
}
private static object lockObject = new object();
private static A instance;
public A Instance
{
get
{
if( instance == null )
{
lock( lockObject )
{
if( instance == null )
{
instance = new A();
}
}
}
return instance;
}
}
} This ensures that only one instance is ever created and makes it so you don't have to be passing that instance all over the place.
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
Would all that be required? Wouldn't:
private static A Instance = new A();
Be the same?
Of course, I could be having brain fade here...
Rocky Moore <><
|
|
|
|
|
It would be similar, the difference being that you delay the creation of A until you actually need it. That could be important if A were a "heavy" object. Then to ensure you don't create 2 instances of A by having two threads run the getter the first time, you need to lock on an object.
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
Actually, the instance will not create until the first time you access it. I made a simple test application. I put debug information in the contructor and the property get of the class. Then in the code where I actual reference it, I put a debug statement before and after it. The order was:
Before
Constructor
Get
After
I wonder what would happen in multiple threads though, wouldn't you think .NET would take care of that since it is a static?
Just my curiousity is up
Rocky Moore <><
|
|
|
|
|
Rocky Moore wrote:
I wonder what would happen in multiple threads though
Here is a nice article on MSDN that discusses the Singleton design under the .NET Framework, including multithreading issues.
Exploring the Singleton Design Pattern[^]
-Nick Parker
|
|
|
|
|
Hey, thanks for the link. Glad to hear that the .NET framework does handle the threading issues automatically and that my VS.NET was not possessed, that the object is only created when first accessed They are really making some things a lot easier in .NET. Can hardly wait for a few more versions down the road.
Anyone know how Mono handles this situation?
Rocky Moore <><
|
|
|
|
|
James, the singleton implementation works absolutely great, that's just what I needed. Thanks again.
-Nick Parker
|
|
|
|
|
Singletons are .
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
get
{
if( instance == null)
{ lock( lockObject)
{
if( instance == null )
{
instance = new A();
}
}
}
}
James, in the above code, why do you have to check for null two times, isn't that because of the threading issue, like before locking up the object if some other thread has accessed the property thus creating an instance
thanks,
Kannan 
|
|
|
|
|
Kannan Kalyanaraman wrote:
isn't that because of the threading issue, like before locking up the object if some other thread has accessed the property thus creating an instance
You got it
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
Thank you, James
- Kannan
|
|
|
|
|
When printing a DataGrid using InvokePaint(myGrid, myPaintArgs) there is a small artifact in the upper left of the print-out. It goes away if the ColumnHeadersVisible property is set to false. I have tried setting the DataSource before setting this property to true thinking it might be a re-size issue.
Is anyone aware of a fix for this problem? Or have any other ideas of what might be causing it?
Thanx...
>>>-----> MikeO
|
|
|
|
|
I've been through several books on C# and its data types but I haven't found how to create records. If I have a definitions/classes where I'm trying to define addresses, everything about addresses is consistent between a shipping address, personal address, billing address, etc.
Please bear with the example and qualify/disqualify my understanding since I am converting from Delphi/Pascal.
My understanding of the C# implementation says I can't do something like (Delphi/Pascal structure):
Type TAddress = Record
AddressID : Integer;
Address : String;
City : String;
State : String;
ZipCode : String;
Country : String;
end; {TAddress}
and then define the variables:
private string PersonName;
private TAddress PersonAddress;
The impression is that I must create a class called TAddress with each field being a property that has a Set and Get attribute. Is this the case? I cannot create a new datatype without it being a class?
Along those same lines, if I want a "Globals" or "Constants" file, I would need to create a class and define each Global/Constant as a public variable. Are there pros/cons between creating a them as public variables verses as properties with a Get.
Thanks.
|
|
|
|
|
Well, here's what it sounds like: You need an Address type that you can use for shipping, billing, and personal addresses. You want to know if you can define a type without it being a class, you want to know the differences between properties and fields, and you want to know about globals...right? (If not, correct me. )
1) As for the address type. The proper way to define that in C# as a class would be:
public class Address
{
public int addressID;
public string address;
public string city;
public string state;
public string zipCode;
public string country;
}
However, because you don't really have any methods that belong to the Address class, and because you are really just holding data in this class, I would make it a struct. This makes it a value type that gets created on the stack rather than the managed heap. So just change the word class to struct.
Then somewhere else in your code you could do something like this:
Address personalAddress = new Address();<br />
personalAddress.addressID = 1;<br />
personalAddress.address = "123 Anywhere St."
Or even better, you could define a constructor for your struct/class that would let you specify some of the fields so that you don't have to do so much typing.
2) The difference between a property and a field is that the property is really just a pair of accessor methods for the field. You still need to define the field so that the property can store information. But the benefit of properties is that you can perform validation on the data that gets passed in or perform some action at the same time. They're really quite useful.
3) There isn't any concept of a global field/method/property/whatever in C#. The closest you're going to get is to define a class and have each member be public static. That way you don't have to instantiate a member of the class in order to act on that field/method/...
If you need any further clarification don't hesitate to ask. Hope that helps.
Hawaian shirts and shorts work too in Summer.
People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage...
-Anna-Jayne Metcalfe on Paintballing
|
|
|
|
|
for globals which is an insanely ugly world in programming and leads to all sorts of foobar'd results.
but the constants or actually enums I use I store in a main namespace, constants is more of a Java thing I think
namespace myIgnorantEnums
{
public enum Mine
{
None,First,Second,Third
}
}
then in your class file
using System;
using myIgnorantEnums;
Thats all there is to it but I would organize it in which the namespace it actually belongs to.
Look at the Data library, especially SqlTypes of that particular namespace.
|
|
|
|
|
Dave & Ista -
Thanks. That is exactly what I was looking for. Didn't even recognize the structs as the tool to use but, after reading on them, I believe that is exactly what I need. As for "Globals", you are right. "Constants" is the proper term. None of what I am referring are variables. The constants file will consist of the struct/classes, as discussed, enums and constants that are used through out the program but are not specific to a certain class.
Thanks. 
|
|
|
|