|
I had posted this question last friday, but havent found a solution yet, so posting it again in case somebody is aware of the solution.
** Original message **
Hello,
This is my code which will convert the ADO resultset to XML in C#.
I actually need the column type, column max length etc also in the xml, like the column type/length of id, loginuserid, deptid, wrkstnid etc.
So I am not sure whether I need to pass some parameters to SqlDataAdapter class while executing the SQL command or the XmlDataDocument class has some methods which would print out the datatype and column length information in the XML. Looked at both the classes, didnt find any method, anybody has any ideas about this? Thanks
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds);
if (ds.Tables.Count>0)
{
_sBody = new StringBuilder("", _bodySize);
//Get xml representation of the dataset
XmlDataDocument srcXML = new XmlDataDocument(ds);
srcXML.Save("c:\\XMLDocument.xml");
....
}
<NewDataSet>
<Table>
<id>1</id>
<LoginUserId>tpmadmin</LoginUserId>
<DeptId>1</DeptId>
<WrkstnId>1</WrkstnId>
</Table>
<Table>
<id>2</id>
<LoginUserId>sysadmin</LoginUserId>
<DeptId>2</DeptId>
<WrkstnId>2</WrkstnId>
</Table>
</NewDataSet>
-----------------------------------------------
** Paul Brower's Reply **
Try this, (with 'ds' being your dataset)
ds.WriteXml(@"c:\thedataset.xml",System.Data.XmlWriteMode.WriteSchema) ;
That will write out all your xml with the schema.
-----------------------------------------------
** Question **
I actually want the max size of the column and I think that information is missing in the XML. The XML looks something like this. Max size of the column is used by the XSL to print the data. For datatypes like int, numeric, datetime I can manage the column lenght, problem arises only when its of type string, char etc
It has the column name, type, minOccurs. I think the max size of the column is missing, do I need to try some other method, or any other argument? Thanks,
<?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:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:int" minOccurs="0" />
<xs:element name="LoginUserId" type="xs:string" minOccurs="0" />
Thanks.
-- modified at 17:47 Monday 8th May, 2006
|
|
|
|
|
Thread[] workerThread = new Thread[someInt];
for(int i = 0; i < someInt; i++)
{
string keyInfo = someKeyInfo().ToString();
workerThread[i] = new Thread(new ThreadStart(DoSomeWork(keyInfo)));
workerThread[i].Start();
}
foreach(Thread t in workerThread)
{
while(t.IsAlive()){}
}
|
|
|
|
|
I didn't think called methods could have parameters in Framework 1.1. The methods used by ThreadStart must be static.
|
|
|
|
|
First point is correct but .Net 2.0 has a new overload for the Thread constructor accepting a ParametrizedThreadStart. Second point isn't true even under 1.1 also 'normal' functions can be used.
|
|
|
|
|
Depending on the number of threads you could consider using ThreadPool.
Also you should rethink the IsAlive loop. First of all it could consume much processor time so you should at least do:
foreach(Thread t in workerThread)
while(t.IsAlive())
Thread.Sleep(10);
Instead of waiting for all threads separately you could also use a counter which counts the started and terminated threads. Have a look at the Interlocked[^] class for a sample.
|
|
|
|
|
Robert is right, just don't go thread crazy. Also, I don't know if it's still an issue on uniprocessor machines but the child thread won't start unless you call Thread.Sleep(0) in the parent after creating it.
|
|
|
|
|
If you are going to do something like that use:
foreach(Thread t in workerThread)
{
thread.Join();
}
I'd only do something like that in a simple console application and I didn't care about the results of the DoSomeWork method. Otherwise I'd use asyncronous delegates and callback methods.
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 have several threads, calling the same function.
This function does not access any global stuff... Only variables created inside it.
If I have something like this:
void foo()
{
int x = 100;
}
Is a new instance of x being instantiated for every call a thread makes?
Or is the same instance of x being used over and over...?
|
|
|
|
|
It is declared locally so every thread will have its own value.
|
|
|
|
|
Thank you very much...
I'm new to threading... And I have a bug in my program...
So I just wanted to make sure it's not the reason.
Thanks again...
|
|
|
|
|
Im getting "The Server is not operational" when authenticating user to active directory
Any help plzz...
Thanks in advance
Krishna
|
|
|
|
|
Hi,
I'm displaying a web page in a windows form. Now that the page is displayed, I want to be able to set the cursor to a specific position, and then move it until it reaches another location on the page. The second location has no ID, no name and that is why I'm approching the question like that.
I'm new to C#, so if anybody can help...
|
|
|
|
|
I couldn't realy understand...
Are you looking for a function which sets the cursors position?
If you are, you can use the SetCursorPos API function...
I doubt that there's any .NET implemented function to do this...
Best regards,
Shy
|
|
|
|
|
How would I add text to a listbox and have that text added to the top line instead of the bottom line?
|
|
|
|
|
try doing the same function you do but backwords.
i.e: insted of:
for (int i = 0; i < n; i++)
write:
for (int i = n-1; i => 0; i--)
or
for (int i = n; i > 0; i--)<br />
i-1;
etc...
another way is to use a DataSet to arrange the stuff up... (may be longer)
that's all I can think of (without looking at properties etc...)
yours, NaNg.
|
|
|
|
|
hi JMichael2468!
Instead of using the ListBox's Items.Add method, use the Items.Insert method.
then pass a zero value in the index parameter so it will be added on top of the collection.
i tried it and it works fine with me.
hope this helps!
microsoc
|
|
|
|
|
|
Hey all... I know a little C#, I've been working with it for 2 years (still at school, 11th grade), I'm pretty expirienced but still I don't know alot... I'm building all my programs on VC# express, which as you know, has built-in publisher, with built-in installation, well, I wanna do a few things out of the small box it shows me, so here are some questions that I remember now, that I would like answers to them, and appriciate if you would answer, or give me a link for it:
1. How can I register my program in such a way, that the computer will know that files with endings such as what I want(i.e .ysl) will have an icon that I want?
2. How can I register my program in such a way, that I can put an option of "Start with Windows startup"?
3. What is the BEST way to make sure that my program is only run ONCE in the computer, and that no-one will be able to open another copy will the first one is running?
4. How can I open a process (System.Diagnostics.Process), and make sure it's an internet explorer program, such as IE or NetScape no-matter to the program he use (IF statements will be accepted), and open it in a URL I want?
5. How can I tell who implements ICryptoTransform (System.Security.Cryptography.ICryptoTransform) without checking at Microsoft's MSDN for each and every one? and what is the best way to encode (Crypt) my code (what is the best ICryptoTransform implementing class to do it)?
6. Where can I find default icons such as SaveAs... (three discates), Save (one discate), open (folder), new (page) etc...?
well... that's enough for now... if I'll remember some more I will ask...
THANKS IN ADVANCE FOR ALL THE ANSWERS!!!!
-- modified at 15:51 Monday 8th May, 2006
|
|
|
|
|
sorry for the multiple posting, the site said and error and I thought it didn't post it, if the admin can erase one please, but leave one also, that would be lovely ...
thanks...
|
|
|
|
|
This happens from time to time.
You can erase your postings on your own. There is a delete link at the right side of bottom edge.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
3. Search for "single instance" here on Code Project. There are some articles covering this topic. (By the way this should be done everytime before asking a question in the forum).
1. I think there are articles too which cover this topic.
2. Where do you want to put this option? If you want to start your application with windows startup, simply create an appropriate link in the Autostart folder of startmenu.
4. Process.Start("www.troschuetz.de"); //Opens URL with standard browser
6. Not sure, but maybe searching for "*.ico" on C-partition brings some results. Also googling for "ico" or "icon" and "SaveAs", "Save" or ... may be worth a try.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
1. Create some registry entries under HKEY_CLASSES_ROOT:
This can all be done programatically, but it takes some work. Look at the Microsoft.Win32 namespace for registry manipulation functions.
1) Create a key by the name of the file extension you want
2) Set the default attribute of this key to a word that describes your program. It's name doesn't really matter.
3) Create a key by the name of the word you decided on in step 2.
4) Create some subkeys: 'DefaultIcon' and 'shell'
5) Set the default attribute of the DefaultIcon key to the path of your icon. If you want to use the the same icon
as your executable, do something like this: <code>c:\code\mysupercoolapp\exefile.exe,0</code>
6) Create a 'open' subkey under 'shell' and a 'command' subkey under open
7) Set the default attribute of the 'command' key to the path of your program (include the %1) <code>c:\code\mysupercoolapp\exefile.exe %1</code>
8) Restart
9) When a file with the extension you've picked is double-clicked, your application will run.
The first argument will be the path of the file.
2. You can put a link in the startup folder of the start menu, or add a registry entry to either
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
(if you want it to run whenever the computer starts)
or
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
(if you want it to run whenever only the current user logs on)
3. As the other post-er said, search for "single instance"
4. System.Diagnostics.Process.Start("http://www.myurl.com"); will open the url in the default web browser
5. I should read up on cryptography
6. They are in a zip file in Visual Studio's program folder:
C:\Program Files\Microsoft Visual Studio 8\Common7\VS2005ImageLibrary\VS2005ImageLibrary.zip
(or similar)
Hope this helps,
DigitalKing
|
|
|
|
|
thank you very very very very very very very very much!!!
Both of you!
|
|
|
|
|
the Process.Start("http://..."); method is opening the URL in the already opened browsers, how can I turn it to new browsers?
|
|
|
|
|
There's no good way to accomplish this, as it is the user's preference.
For example, in firefox, the user can select whether to load newly opened pages in the current tab, or a new tab.
|
|
|
|