|
Use CultureInfo.CurrentCulture to get what language is set in the regional options (for formatting dates, times, and numbers). Use CultureInfo.CurrentUICulture to get the current language pack installed and in use. The CLR sets this automatically when the application is started, but you can also set the similarily named properties on the Thread class to override the default regional and language options.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
My best guess is that C# was designed this way on purpose... with garbage collection in mind, but here's the problem.
I have a dataSet that I initialize with XML data. Let's call it ds. I then load the ds into a dataGrid (dg). However, I want to modify the appearence of the data first. So here is what I have done:
<br />
<br />
<br />
public void BindDataGrid()<br />
{<br />
DataSet temp = ds;<br />
<br />
temp.AcceptChanges();<br />
dg.DataSource = ds;<br />
dg.DataBind();<br />
}<br />
The DataGrid looks good, but it turns out that temp was apparently just a pointer to ds because ds also reflects the changes I made to temp? How do I create and use a temporary dataset without modifing the original?
|
|
|
|
|
Use Clone to copy the structure of the DataSet , but not the data. Use Copy to copy both the struct and the data. This is documented in the .NET Framework SDK for the DataSet class.
In .NET, there are no pointers, but references for reference types. Assigning a new variable an instance of an object makes that variable reference the original object. Value types work differently, however. Value types are structs, primatives (which are reflected by structs), and enumerations. Passing a value type as a parameter is always pass by value, unless you use the out or ref keywords. This is important to understand with object-oriented frameworks like .NET and Java.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Well!
You could copy the dataset into temp:
DataSet temp = ds.Copy();
.NET almost always creates references to objects while "copying them", so there's a unique object in memory with lots of references to it, thats what you created with temp = ds.
Anfernius
|
|
|
|
|
Any time you do an operation
a = b;
your are creating a pointer basicall making two references to a single object. An object is created in the heap, b has reference to that object, and a now has reference to that same object. It is more the rules of objects rather than a way it is done in C#.
To get a copy of the object depends on how the object is implemented. Now opening the Object Browser and searching for DataSet, when I select it I see that the Dataset object exposes ICloneable by the presence of the Clone() method.
So what you need to do is this:
a = b.Clone();
This will give you an independant clone of the object (without data as documented in the Object Browser) and allow you to change it to your hearts' content without impacting what you place in the datagrid.
Or you can do a = b.Copy() which will copy the structure and the data (as document in the Object Browser).
The object browser will give you quite alot of information on the various classes within the framework. You can run the Object Browser from the View menu option in Visual Studio. Use the binoculars icon to search for DataSet and then select the various methods to get a description of what they will do for you.
Enjoy.
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
I've got a class that has a Color property.
class MyClass
{
public Color Color
{
get {return color;}
set
{
color = value;
.... some other processing here ....
}
}
.... some other properties and stuff here ....
} All other members of the class serialize correctly into XML, but all I get for the Color property is a <Color /> tag output. Presumably the Color struct just doesn't serialize of it's own accord, so does anyone know a tidy way to XMLize the Color correctly?
Joel Holdsworth
Wanna give me a job over the summer?
View my online CV and Job Application[^]
|
|
|
|
|
|
Hmm... yes that looks pretty good for actually making a string representation for the Color, but how do I get that string representation to appear as the property value in the XML?
Joel Holdsworth
Wanna give me a job over the summer?
View my online CV and Job Application[^]
|
|
|
|
|
I'm developing a Windows CE .NET application.
How can I make a floating toolbar in my .NET Compact Framework application?
As alternative, can I visualize a toolbar upon the title of my form instead of inside (and on the top of) the form itself?
|
|
|
|
|
hello -
I just upgraded to VS.NET 2003 and now some of my crystal reports don't seem to work. The reports appear to run but the report viewer comes up empty. I checked all the references and I believe they are current and pointing to version 9.1.5 of the new crystal decision dlls...anyone know what the problem is?
|
|
|
|
|
Did you go to www.gotdotnet.com [^]and check the differences between 1.0 and 1.1 as it pertains to Crystal Reports ??
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
actually, we just ended up installing the Crystal Reports monthly hot fix and using the newest merge modules for VS.NET 2003 and now it works fine. Guess in an ideal world, we should have had to apply a patch for a 2003 upgrade but seems fine now. thanks.
|
|
|
|
|
Hi,
I need to send changes to database in web service sitting on another machine with DB. I was thinking of using the following code in order to
do the update:
<br />
<br />
SqlConnection myCon = new SqlConnection(sCon1);<br />
SqlDataAdapter da = new SqlDataAdapter();<br />
<br />
da.SelectCommand = @"INSERT INTO MidnightReadings " +<br />
"(MR_Date, Coal_Feeder_Tot, Coal_Silo_Level_Prct, Coal_Barn_Inv_Prct, Limestone_Feed_Total, LS_Silo_Level_Prct, Ammonia_Totalizer, " +<br />
"Prop_to_Burn_Totalizer, TwentyFourHr_SO2_Reduct, Limestone_Received, Ammonia_Received, Prop_Received, Est_hours_Dry_Oper_Hours, " +<br />
"Est_hours_Dry_Oper_Mins, LAB_Sulfur_Content_Prct, LAB_High_Heat_Val, CEMS_SO2_Daily_Avg, SO2_Daily, Raw_Water_Pump_Meter, " +<br />
"Reservoir_Level, Comments, Date_Rec_Added) " +<br />
"VALUES(@MR_Date, @Coal_Feeder_Tot, @Coal_Silo_Level_Prct, @Coal_Barn_Inv_Prct, @Limestone_Feed_Total, @LS_Silo_Level_Prct, " +<br />
"@Ammonia_Totalizer, @Prop_to_Burn_Totalizer, @TwentyFourHr_SO2_Reduct, @Limestone_Received, @Ammonia_Received, @Prop_Received, " +<br />
"@Est_hours_Dry_Oper_Hours, @Est_hours_Dry_Oper_Mins, @LAB_Sulfur_Content_Prct, @LAB_High_Heat_Val, @CEMS_SO2_Daily_Avg, " +<br />
"@SO2_Daily, @Raw_Water_Pump_Meter, @Reservoir_Level, @Comments, @Date_Rec_Added); " +<br />
" SELECT MR_ID, MR_Date, Coal_Feeder_Tot, Coal_Silo_Level_Prct, Coal_Barn_Inv_Prct, Limestone_Feed_Total, LS_Silo_Level_Prct, " +<br />
" Ammonia_Totalizer, Prop_to_Burn_Totalizer, TwentyFourHr_SO2_Reduct, Limestone_Received, Ammonia_Received, Prop_Received, " +<br />
" Est_hours_Dry_Oper_Hours, Est_hours_Dry_Oper_Mins, LAB_Sulfur_Content_Prct, LAB_High_Heat_Val, CEMS_SO2_Daily_Avg, " +<br />
" SO2_Daily, Raw_Water_Pump_Meter, Reservoir_Level, Comments, Date_Rec_Added FROM MidnightReadings WHERE (MR_ID = @@IDENTITY)";<br />
<br />
SqlCommandBuilder cb = new SqlCommandBuilder(da);<br />
<br />
da.Update(dsDiff,"MidnightReadings");<br />
myCon.Close();<br />
<br />
Does the code look correct for building my update?
Heath had said this is the most efficient way in order to update db.
As you can see my insert statement is big. Is this common to have such a
big sql statement or is there a short version I should be using?
Thanks,
JJ
|
|
|
|
|
As far as the length of the command is concerned, the more information you get into one command is better, since you don't have to reopen the sql connection, and execute multiple commands after each successive command is executed. So, its perfectly fine to do so.
|
|
|
|
|
Hi,
With the way I have this setup do I also have to add parameters to the DataAdapter for each of the values?
JJ
|
|
|
|
|
yea, you definately want to do that!
|
|
|
|
|
If the User hit's the "Close Window"-Button (on the right upper corner) the window should be hide.
How can I stop the closing process and set a this.Hide(); command?
Thanks!
Ariadne
|
|
|
|
|
You want to setup an EventHandler that will handle the ClosingEvent in the form. To be capable of closing the form eventually, you need to manage the state of shutdown. (Was it invoked by me or was it invoked via the X button being clicked?) A [Close] button would handle the actual shutdown and the Closing event handles what to do based on the current state of the form.
So you have something like this:
using System.ComponentModel;
...
this.Closing += new CancelEventHandler(this.ClosingEventHandler);
bool ShutDownInvoked = false;
...
public void CloseRequested_Click(object sender, EventArgs e)
{
ShutDownInvoked = true;
this.Close();
}
public void ClosingEventHandler(object sender, CancelEventArgs e)
{
if (ShutDownInvoked)
return;
this.Hide();
e.Cancel = true;
}
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
Handle the Form.Closing event (or override OnClosing in a derivative class), set CancelEventArgs.Cancel to true and call Hide :
public class MyForm : Form
{
protected override void OnClosing(CancelEventArgs e)
{
e.Cancel = true;
Hide();
}
private void mnuFileExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
} There's other things you can do, such as handling the proper Windows messages like WM_QUERYENDSESSION or WM_ENDSESSION , but you may not have to (and familiarity with Windows messaging is helpful).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
This has been done so many times it's not even funny, but what is funny is I can't figure out the correct phrase to type into google to find my answer. I need to shorten a paragraph of text into a summary of about 20 to 25 words followed by '...'. Using C# of course. What phrase would you use in google to search for such a method?
I made my own kewl little solution... let me know if you can think of a better way ...
<br />
string temp = mystring;<br />
if (temp.length > 200)
{ <br />
temp = temp.substring(0, 200);
<br />
temp = temp.substring(0, temp.lastIndexOf(" ")) + "...";<br />
}<br />
|
|
|
|
|
int len = mystring.Length > 200? 200: mystring.Length;
string temp = String.Concat(mystring.SubString(0, len), "...");
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
I am building a "generic" web service testing app in c#. The way I have it working now is I add the Web Reference in the IDE and compile. The prog will go type discovering for any class that inherits System.Web.Services.Protocols.SoapHttpClientProtocol in the assemblies of the current domain. It then lists out the methods and associated params available in that class. It will also get the definition for all the classes the respective namespaces of the WS classes and provide an "editor/viewer" of those complex types to either view return values of method calls or create instances of those complex types for use as input parameters to the web method.
What I would like is for my app to be able to:
- call wsdl to generate the .cs for for the web sevice (already done and working)
- call csc to compile it into a library (already done and working)
- Load the dll in the current assembly so that it "typed discovered" and instinciated. (type discovering works but instinciation raises a TargetInvokationException)
I get the dll as a byte[] and then load it with AppDomain.CurrentDomain.Load(rawAssembly). The assembly load correctly, the types are browseable but I can't instinciate them.
Thanks for your time, Louis.
My witty signature.
|
|
|
|
|
There was a recent article in MSDN that covers the two alternatives and how to use them. See Code Generation in the .NET Framework Using XML Schema[^]. It also discusses building types from WSDL - which of course you compile into an assembly - though it leaves much of the implementation to the reader. The basics are discussed.
If you're new to building assemblies (building types and filling in IL, aka "Reflection emit") or using the CodeDom, read Emitting Dynamic Assemblies[^] and Generating and Compiling Source Code Dynamically in Multiple Languages[^].
Why do you need to build an assembly to dynamically invoke methods on an XML web service, though? The classes already support configuring a class and you can always use HttpSimpleClientProtocol.Invoke to invoke methods (and properties, since they're just getter and/or setter methods). See the System.Web.Services.Discovery namespace documentation in the .NET Framework SDK for more information about classes and methods which help you discover information at runtime that you can use to "build" and invoke methods on the XML Web Service without having to compile an assembly at all.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The reason I wanted to go with a compile approach is that I am more familliar with type discovery than I am with code generation using XSD. The main reason why I compile the assembly is go get the definition of the complex types to provide the user with an editor and so, I need the definition of the classes. I got that from the Type definition. Also, I use the Parse function of ValueType types to easily convert from a string to the actual type. I will look into using the type builder from xsd and then use them in the call to HttpSimpleClientProtocol.Invoke if need be. It would have been nice though to consume a DLL that is build for you by .NET SDK tools instead of parsing the WSDL and build the types in code.
Thanks, Louis.
|
|
|
|
|
Instead of using Parse , use the TypeConverter . Often, the TypeConverter for a particular Type will use a Parse method if it exists, but using a TypeConverter (which you can get using TypeDescriptor.GetConverter ) is abstract.
Also, what I mentioned before is that the classes in the .NET FCL already do the discovery for you, providing method names along with their parameters. Than all you have to do is use Invoke . Generate a source file for an XML Web Service in VS.NET, for example. Then show hidden files in your project and look at the source code. You'll see this is all the source code contains.
Compiling and loading assembly has further overhead because not only is it unnecessary, but you can't unload an assembly from your AppDomain . So, if someone uses your application for a while with many different web services, the machine will be at a loss for memory and - even with proper disposing and garbage collection (though you should rarely force it) - your application will grind the system to a halt (or slow enough that users may think the machine has froze).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|