|
You could keep a list of the forms that are open and create a handler that is assigned to every form's Form.Closed event. This handler then iterates over your list of forms and closes each form in succession (via a call to Form.Close() ). Of course you would have to skip over the form that was already closed.
Once that is done you could then just call Application.Exit() as per normal.
Actually, thinking about it: this is a good candidate for an ApplicationContext . Have a look at the example on the ApplicationContext Overview page in your SDK (the example isn't on the MSDN page, sadly), that example is similar to what you want. It could be easily extended.
This space for rent!
My Blog
|
|
|
|
|
Actually, I should've thought more before I posted that. It won't work as each call to Form.Close() will result in the Closed event firing again, which will cause some strange behaviour.
You could simply make a direct call to Application.Exit when the Closed handler is executed, since Application.Exit does not fire the Form.Closed event.
It's probably a little messy, but it's how I would do it.
This space for rent!
My Blog
|
|
|
|
|
I've been working with Nick's suggestion; seems like I have to go back to the SendMessage function... Thanks Adam
"Being smart is no good until you find out who else is?"
|
|
|
|
|
I am working through an exsiting application and it has very few try catch blocks and is letting errors pass straight to the error web page. I make liberal use of try catch blocks am I overdoing it? How expensive is a try catch block am I missing something?
|
|
|
|
|
The only reason for a catch block is to handle the exception by performing a task or adding additional information to the exception and rethrowin. Not just logging the exception and rethrowing, if exceptions are recorded, they should only be recorded once.
Finally blocks/using statements should be used to clean up state like disposing of database connections.
Most of the time exceptions should be so severe that the error web page, or a custom application level handler is the best way to handle them. One rule of thumb I use is that code in catch and finally blocks should be unimportant to the actual working of the application. If you have any logic in your application that requires the catch block for it to work correctly then the code is in the wrong place.
As far as performance goes, for a typical asp.net application accessing a database, each request could throw and catch hundreds of exceptions and performance probably would not be affected because network access is so slow compared to processor time. So for most moderately well written applications most time is spent waiting for database response or sending and recieving data to the client.
So, don't avoid catches because of performance issues. Use them to make your code easier to read and avoid them where it makes it more difficult.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
andy brummer wrote:
The only reason for a catch block is to handle the exception by performing a task or adding additional information to the exception and rethrowin.
I would hope that's not your mantra. End users should never see exceptions. This is no better than showing them AV exceptions in native code, or even the dreaded blue screen of death.
Exceptions are for whatever you need them for, whether that's recovering from an issue, ignoring certain known problems, logging, adding information and rethrowing, etc.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Sorry, left out that part. Every event handler in a Forms application should have a catch, usually just to log and show a generic error message, hopefully more if there is better information to give the user.
In ASP.Net a general error handler is usually sufficient. If you can do something better at the page level then add a handler there. Only after that should you add a catch handler to one of the events.
Unfortunately I've seen
try
{
}
catch (Exception e)
{
throw e;
}
way too many times, and let the rant out in my answer.
What I tried to get through with my answer was that exceptions are there to make your code easier to read and debug. What I was trying to get through is you should use it for the reasons you stated.
However, detecting invalid input by catching an exception from int.Parse would probably be a bad way to structure your application when there is a cleaner way to validate user input. Typically the arguement against it is performance, which would be the case in something like a batch processing application. For an ASP.Net page that wouldn't really apply, because you are sending information over the network.
So, for validating user input on an ASP.Net page I would either use the built-in validation controls or write custom validation code for all the input that would not throw exceptions under all input that I could test, and use a generic exception handler for cases that truely are exceptional and provide a relatively friendly error message to the user for that case.
This was way too long of a reply considering we both have similar views on exception handling. I just come across as more of a jerk online.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
I've got a couple of things that I'm still working on the conversion of C to C#
// **** begin sample C code **** //
unsigned char *tempvar = "1989";
unsigned char dataArray[256]; // hex value stored in this array with year in location 0xC0;
char* Message;
if (!strncmp(dataArray + 0xC0, tempvar, 4)) Message = "different data!";
// **** end sample C code **** //
What I'm trying to do is to compare the data in location 0xC0 in dataArray with tempvar.
Now the question is... I'm trying to determine the correct coding for C#. Correct me if I'm wrong.
// **** begin convert to c# code **** //
string tempvar = Convert.FromBase64String("1989");
byte[] dataArray; // hex value stored in this array with year in location 0xC0;
if (tempvar.CompareTo(Convert.ToBase64String(dataArray, 0xC0, 4)) != 0) Message = "different data!";
// **** end convert to c# code **** //
|
|
|
|
|
Hex != base64. Hex is base16, which is obviously not base64. To hex-encode integers you can use their IFormattable.ToString implementation. This could be done like so:
int value = 1989;
string hex = "0x" + value.ToString("x4"); This will hex-encode 1989 into a four-digit hexadecimal representation to look like "0x07c5".
You don't need to conver to hex, however. Hex is only a representation of numbers. Your tempvar in the C code will contain the bytes {0x31, 0x39, 0x38, 0x39}. Those are strings, though - they're numberic expressions for the ANSI characters (since you're using a char array, they are only 8-bit character using the codepage you specify when compiling (default of system codepage).
Also keep in mind that a char* or char[] is a string. A string is just an array of characters. So if dataArray was a byte[] array like in your example (meaning ANSI text, not Unicode like .NET uses to encode stored strings), then you'll need to convert your string "1989" to a byte[] array using ASCIIEncoding and compre the buffers at that offset:
using System;
using System.Text;
class Test
{
static void Main()
{
byte[] text = Encoding.ASCII.GetBytes("1989");
byte[] dataArray = new byte[256];
int i = 0xc0;
dataArray[i++] = 0x31;
dataArray[i++] = 0x39;
dataArray[i++] = 0x38;
dataArray[i++] = 0x39;
bool found = true;
for (i=0; i<4; i++)
if (dataArray[0xc0 + i] != text[i])
found = false;
Console.WriteLine(found);
}
} An easier way is to just convert the 4 elements starting at offset 0xc0 from dataArray into a string and compare it:
using System;
using System.Globalization;
using System.Text;
class Test
{
static void Main()
{
byte[] dataArray = new byte[256];
int i = 0xc0;
dataArray[i++] = 0x31;
dataArray[i++] = 0x39;
dataArray[i++] = 0x38;
dataArray[i++] = 0x39;
byte[] text = new byte[4];
Array.Copy(dataArray, 0xc0, text, 0, 4);
string s = Encoding.ASCII.GetString(text);
bool found = string.Compare("1989", s, true,
CultureInfo.InvariantCulture) == 0;
Console.WriteLine(found);
}
} You should read up on string encoding for more information. Also note that compilers treat various numerical expressions the same, so:
0xC0 == 192 == \300 They're all just different representations of the same numbers, so don't confuse hex-encoded values as string to compare.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi guys,
I have a problem where the user clicks a button to launch a fairly processor intensive task. After pressing, the button becomes disabled, and the task is set running.
The problem is that if I press during the task (the text is grayed so I know it actually has been disabled) as soon as the computation has completed and the button is re-enabled, it remembers the button press from earlier and runs again
Any Ideas?
Mike
|
|
|
|
|
mikey_g wrote:
The problem is that if I press during the task (the text is grayed so I know it actually has been disabled) as soon as the computation has completed and the button is re-enabled, it remembers the button press from earlier and runs again
Any Ideas?
Hmm, that sounds strange, I would like to see the code. I put together a simple app that is defined as you described above and couldn't recreate it. Check the following:
using System;
using System.Threading;
using System.Collections;
using System.Windows.Forms;
public class MyClass : Form
{
Button b;
private void Initialize()
{
this.b = new Button();
b.Text = "Click Me";
b.Click += new EventHandler(bClick);
this.Controls.Add(b);
}
private void bClick(object sender, EventArgs e)
{
b.Enabled = false;
DoLongProc();
b.Enabled = true;
}
private void DoLongProc()
{
Thread.Sleep(5000);
MessageBox.Show("Done now");
}
public static void Main()
{
MyClass m = new MyClass();
m.Initialize();
m.ShowDialog();
}
}
|
|
|
|
|
Ok, it was my bad coding. What was happening was that I hadn't run the processor intensive code in a thread, it was all inline stuff.
This was causing the window to not fully respond to input and the click was only handled once the process was finished, ie, once the button had been re-enabled.
Thanks for the help as it put me ontrack
Mike
|
|
|
|
|
Hi all, anyone know if the XML Bulk Loader can be used in C# instead of from a vb script?
Is there a namespace or anything that i can include?
Kev
|
|
|
|
|
It can be used as a COM object. You have to create a Primary Interop Assembly (PIA) first and then you can make it work. With the latest version of sqlxml (service pack 3), you can just add a referece from the COM tab of the Add Reference dialog (see this article to see how the reference is added: http://www.dbazine.com/cook3.shtml[^] ). Visual Studio will generate the PIA automatically and add it as the reference in your project. Keep in mind though, that the PIA that it creates doesn't get created with a strong name, so if you plan to use your C# project from COM+, you will have to re-create it by hand using tlbimp.exe and a .snk (strong name key) file to make sure that it has a strong name.
I have worked with SQLXML from C# quite extensitvely, so let me know if you have any specific questions.
Best Regards.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
I have the Infragistics Calendar control on my form. I am calling the DisplayAppointmentDialog method of the ClendarInfo object and the dialog is being displayed fine. How can I control the controls on that dialog to customize it?! For example, the dialog has an Action tab. What can I do to remove this tab, or disable it?!
Elie
|
|
|
|
|
You probably won't find many responses to this question as this forum is specific to problems with the C# language, not third party controls. You might check the Infragistics Support site here[^] for additional help. Good luck.
|
|
|
|
|
Hi
I have done aprogram in c# such that , my program reads a schema file and automatically loads data into a xml file.
ex:
consider the following schema
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns:xs="http://://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="en-AU">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="vw_forecast">
<xs:complexType>
<xs:sequence>
<xs:element name="billto_name" type="xs:string" minOccurs="0" />
<xs:element name="dividend" type="xs:float" minOccurs="0" />
<xs:element name="section" type="xs:double" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
</NewDataSet>
We can see that there are three fields namely billto_name, dividend and section.
so my program reads this schema file and loads data automatically by obtaining the following xml file
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="en-AU">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="vw_forecast">
<xs:complexType>
<xs:sequence>
<xs:element name="billto_name" type="xs:string" minOccurs="0" />
<xs:element name="dividend" type="xs:float" minOccurs="0" />
<xs:element name="section" type="xs:double" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<vw_forecast>
<billto_name>Castle Hampers0</billto_name>
<dividend>4.5</dividend>
<section>888888</section>
</vw_forecast>
<vw_forecast>
<billto_name>Castle Hampers1</billto_name>
<dividend>5.5</dividend>
<section>888889</section>
</vw_forecast>
<vw_forecast>
<billto_name>Castle Hampers2</billto_name>
<dividend>6.5</dividend>
<section>888888</section>
</vw_forecast>
<vw_forecast>
<billto_name>Castle Hampers3</billto_name>
<dividend>7.5</dividend>
<section>8888890</section>
</vw_forecast>
<vw_forecast>
<billto_name>Castle Hampers4</billto_name>
<dividend>8.5</dividend>
<section>888891</section>
</vw_forecast>
</NewDataSet>
we can see the values
Now my requirement is that I have another xml file with a single field name "billto_name". with some meaningful values. So I have to program such that if the schema contains a "billto_name" field then load those data's into the result xml.
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="en-AU">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="billtoname">
<xs:complexType>
<xs:sequence>
<xs:element name="billto_name" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<billtoname>
<billto_name>ACCOUNTS CODES ONLY</billto_name>
</billtoname>
<billtoname>
<billto_name>ACCOUNTS CODES ONLY</billto_name>
</billtoname>
<billtoname>
<billto_name>AERIAL PRODUCT RANGE</billto_name>
</billtoname>
<billtoname>
<billto_name>AFL LICENCED PRODUCT</billto_name>
</billtoname>
<billtoname>
<billto_name>AUST RUGBY UNION</billto_name>
</billtoname>
</NewDataSet>
so the values such as AUST RUGBY UNION , AFL LICENCED PRODUCT EVERYTHING SHOUYLD BE INSERTED INTO THE PREVIOUS XML FILE FOR THAT FIELD ALONE.
This is my requirement. I tried a lot but i couldnt suceed
Here is my part of the coding. pls help me out to do this.
private void button2_Click(object sender, System.EventArgs e)
{
dataSet1.ReadXmlSchema(txtSchema.Text);
foreach (DataTable dTbl in dataSet1.Tables)
{
for(int j = 0; j <= 11; j++)
{
object[] oValues = new object[dTbl.Columns.Count];
int i = 0;
string fileName = "C:\\CDEV\\testdatagenerator\\billtoname.xml";
XmlTextReader xtr = new XmlTextReader(fileName);
foreach (DataColumn dColmn in dTbl.Columns)
{
try
{
xtr = new XmlTextReader("C:\\CDEV\\testdatagenerator\\billtoname.xml");
while(xtr.Read())
{
switch (xtr.NodeType)
{ case XmlNodeType.Element:
if((xtr.NodeType == XmlNodeType.Element) && (xtr.Name == "billto_name") )
{
oValues[i] = xtr.Value;
}
break;
}
}
}
finally
{
if (xtr != null)
{
xtr.Close();
}
}
switch(dColmn.DataType.ToString())
{
case "System.String":
oValues[i] = (string) "sachin" + j;
break;
case "System.Int32":
oValues[i] = (int) 100 + j;
break;
case "System.DateTime":
oValues[i] = new DateTime(2004,01,30).AddDays(j * 1);
break;
case "System.Decimal":
oValues[i] = new Decimal(10000900.99) + j;
break;
case "System.Int16":
oValues[i] = (short) 32767 - j;
break;
case "System.Int64":
oValues[i] = (long) 400 - j;
break;
case "System.Double":
oValues[i] = (double) 888888 - j;
break;
case "System.Single":
oValues[i] = (float) 4.5f + j;
break;
}
}
i = i+1;
dTbl.Rows.Add(oValues);
}
}
}
private void button3_Click(object sender, System.EventArgs e)
{
dataSet1.WriteXml(txtXml.Text,XmlWriteMode.IgnoreSchema );
MessageBox.Show("Saved");
}
Hope anyone will help me .
santhosh
|
|
|
|
|
You should break your problem up into smaller pieces and ask specific questions. Nobody is going to answer this because it's too difficult to understand what the problem is. You should start out by explaining what you are trying to do and what problems you are having accomplishing it. I've read through it several times and don't understand what your want to do.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Hi
I have done a program such that the program asks for a xml schema file. Then we have to give out the schema file. the program reads the schema file (for all field names) and according to their datatypes, it automatically creates data's for each fields in a new xml file(about 200 data's).
For example:
"FIRST XML FILE"
for string datatype -> say field name "Name( john1,john2,john3...etc)" for about 200 values
for decimal -> say field name "Salary(9120.88, 9120.89, 9120.90 ..etc)" for about 200 values.This will be our resultant xml.
Leave this apart.
"SECOND XML FILE"
Now we have another xml file with some field name and data's seperately.
This has about 200 values for each field.
In this xml file we have a fieldname called "Name".
So what I want to do is , that coming to my program , My program while reading the schema file , when it comes across the fieldname "Name" then it should read the "SECOND XML FILE" and copy the fieldname "Name" (ie, its data's ) and insert the values into the "FIRST XML FILE" field name "Name". The others should be the same.
This is my requirement.
I tried a lot but i couldnt suceed. Pls help me to do this.
santhosh
|
|
|
|
|
I think I understand a little bit better now, however, I still need some clarification. Here's what I think you're saying--You have a schema file and two XML files. While you are iterating through the fields in the schema, you want to look up the current field in the second xml file and copy the data to a field in the first xml file. Is that correct?
I'll assume it is for a moment. There is a method on the XmlElement object called SelectSingleNode. This method uses XPath to allow you to select a single node based on a query criteria somewhat similar to a SQL query. Here is an example from the Microsoft site:
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("booksort.xml");
//Create an XmlNamespaceManager for resolving namespaces.
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("bk", "urn:samples");
//Select the book node with the matching attribute value.
XmlNode book;
XmlElement root = doc.DocumentElement;
book = root.SelectSingleNode("descendant::book[@bk:ISBN='1-861001-57-6']", nsmgr);
Console.WriteLine(book.OuterXml);
}
}
And here is the related XML file:
<?xml version="1.0"?>
<!-- A fragment of a book store inventory database -->
<bookstore xmlns:bk="urn:samples">
<book genre="novel" publicationdate="1997" bk:ISBN="1-861001-57-8">
<title>Pride And Prejudice</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>24.95</price>
</book>
<book genre="novel" publicationdate="1992" bk:ISBN="1-861002-30-1">
<title>The Handmaid's Tale</title>
<author>
<first-name>Margaret</first-name>
<last-name>Atwood</last-name>
</author>
<price>29.95</price>
</book>
<book genre="novel" publicationdate="1991" bk:ISBN="1-861001-57-6">
<title>Emma</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
<book genre="novel" publicationdate="1982" bk:ISBN="1-861001-45-3">
<title>Sense and Sensibility</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
</bookstore>
I'm not sure if this is going to help you or not, but if I understand your correctly, then you should be able to get the node you're looking for using this method on the first XML file. The key is that you will have to now what you're looking for.
Let me know if I've missed the boat completely here and if so, just clarify what you are trying to do.
Best Regards.
-Matt
p.s. Here is a link to the documentation I got the code from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlNodeClassSelectSingleNodeTopic.asp .
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Hi
I have done a program in c# such that , my program reads a schema file and automatically loads data into a xml file.
ex:we hav e a text box where we give a schema file.
let us give the following schena file
consider the following schema
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns:xs="http://://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="en-AU">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="vw_forecast">
<xs:complexType>
<xs:sequence>
<xs:element name="billto_name" type="xs:string" minOccurs="0" />
<xs:element name="dividend" type="xs:float" minOccurs="0" />
<xs:element name="section" type="xs:double" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
</NewDataSet>
We can see that there are three fields namely billto_name, dividend and section.
-------------------------------------------------------------------------
we have another textbox, where we give a path and a newname xml file . where we get the result.
after giving giving the path where we want to save and the new xml file name and we click a button named load. then values get loaded into the new xml file automatically
so my program reads this schema file and loads data automatically by obtaining the following xml file
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="en-AU">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="vw_forecast">
<xs:complexType>
<xs:sequence>
<xs:element name="billto_name" type="xs:string" minOccurs="0" />
<xs:element name="dividend" type="xs:float" minOccurs="0" />
<xs:element name="section" type="xs:double" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<vw_forecast>
<billto_name>Castle Hampers0</billto_name>
<dividend>4.5</dividend>
<section>888888</section>
</vw_forecast>
<vw_forecast>
<billto_name>Castle Hampers1</billto_name>
<dividend>5.5</dividend>
<section>888889</section>
</vw_forecast>
<vw_forecast>
<billto_name>Castle Hampers2</billto_name>
<dividend>6.5</dividend>
<section>888888</section>
</vw_forecast>
<vw_forecast>
<billto_name>Castle Hampers3</billto_name>
<dividend>7.5</dividend>
<section>8888890</section>
</vw_forecast>
<vw_forecast>
<billto_name>Castle Hampers4</billto_name>
<dividend>8.5</dividend>
<section>888891</section>
</vw_forecast>
</NewDataSet>
we can see the values as castlehampers1,..2..3..4..so on for string datatype and 4.5,5.5,6.5...so on for float..etc...
-----------------------------------------------------------------------
Now my requirement is that I have another xml file in the project directory with a single field name "billto_name". with some meaningful values. So I have to program such that if the schema contains a "billto_name" field then load data's from this xml where we have meaninful fields into the result xml. ie, the previous xml here we obtained data's automatically.
ie, values for billto_name should chanege whereas others should remain unchanged.
this is the xml file with meaninful values. so we should read the values of billto_name from here and load it into the above xml for that particular field.
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="en-AU">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="billtoname">
<xs:complexType>
<xs:sequence>
<xs:element name="billto_name" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<billtoname>
<billto_name>ACCOUNTS CODES ONLY</billto_name>
</billtoname>
<billtoname>
<billto_name>ACCOUNTS CODES ONLY</billto_name>
</billtoname>
<billtoname>
<billto_name>AERIAL PRODUCT RANGE</billto_name>
</billtoname>
<billtoname>
<billto_name>AFL LICENCED PRODUCT</billto_name>
</billtoname>
<billtoname>
<billto_name>AUST RUGBY UNION</billto_name>
</billtoname>
</NewDataSet>
so the values such as AUST RUGBY UNION , AFL LICENCED PRODUCT EVERYTHING SHOUYLD BE INSERTED INTO THE PREVIOUS XML FILE FOR THAT FIELD ALONE.
This is my requirement. I tried a lot but i couldnt suceed
my coding for automatic loading of values is as follows. pls chaneg and sent , as I need this very urgently.
------------------------------------------------------------------
private void button2_Click(object sender, System.EventArgs e)
{
dataSet1.ReadXmlSchema(txtSchema.Text);
//*******txtschema.text is the schema file which we pass
foreach (DataTable dTbl in dataSet2.Tables)
{
object[] oValues = new object[dTbl.Columns.Count];
int i = 0;
foreach (DataColumn dColmn in dTbl.Columns)
{
switch(dColmn.DataType.ToString())
{
case "System.String":
oValues[i] = (string) "sachin" + j;
break;
case "System.Int32":
oValues[i] = (int) 100 + j;
break;
case "System.DateTime":
oValues[i] = new DateTime(2004,01,30).AddDays(j * 1);
break;
case "System.Decimal":
oValues[i] = new Decimal(10000900.99) + j;
break;
}
i += 1;
}
dTbl.Rows.Add(oValues);
}
}
}
private void button3_Click(object sender, System.EventArgs e)
{
dataSet2.WriteXml(txtXml.Text, XmlWriteMode.IgnoreSchema );
//***txtxml.text is the xml file which we obtain as the result
MessageBox.Show("Saved");
}
santhosh
|
|
|
|
|
Hello all,
I need to return more than one Value from methon.how can i do this pleas help
Regards
hay
|
|
|
|
|
|
Usually, if you find yourself in such a need you should reexamine your code and check if it would be better to have a new class to combine and manage the data that you want to be returned.
If this is not the case you can always use the "ref" statement as mentioned in the reply above.
|
|
|
|
|
If you mean to say you might return a string OR an integer as that methods output. You can either
a. Return a structure containing both these thing and at runtime one of them will be null OR
b. return the base class object in the function signature and at runtime it can be either of the derived class objects at runtime.
Option b is cleaner.
If you mean to say you have two values to return from a function in each run use the ref or out keywords to mark those function parameters as modifiable/return values.
Salil Khedkar [^]
|
|
|
|
|