|
You can use sp_procedure_params_rowset 'your_procedurename_here' .
It returns a rowset containing the names, types and other info on the parameters that you procedure takes.
This is the SP that is used by MS in their Data Access Application Blocks (DAAB) for .NET and in earlier versions of ADO.
|
|
|
|
|
I has use your code but it return 0 row effect althought my store have 4 params
can you show me your code??
thanks
Nho'c ti`
|
|
|
|
|
Copy this into a C# Console application:
<br />
SqlConnection cn = new SqlConnection("some_valid_connectionstring_here");<br />
SqlCommand cmd = new SqlCommand("sp_procedure_params_rowset 'your_stored_procedure_name_here'", cn);<br />
SqlDataAdapter da = new SqlDataAdapter(cmd);<br />
DataTable table = new DataTable();<br />
da.Fill(table);<br />
<br />
foreach(DataRow row in table.Rows)<br />
{<br />
Console.WriteLine("{0}", row[3]);<br />
}<br />
"It works on my machine..."
|
|
|
|
|
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.
|
|
|
|