|
|
i have an xml file generated by my program ex.:
<records>
<record id="1" name="test" date="2003-11-17" />
<record id="2" name="test2" date="2003-11-16" />
</records>
and Database table Table1 with structure:
id, int
name, varchar(50)
date, datetime
i want to store this data in database, i can do that by reading rows, step by step, but i search for some basic method, by using DataSet and DataAdapter (i think), i'm using DataSet.ReadXml method to read data from xml file but i don't know how to store it in db table, i were try methods DataAdapter like FillSchema ect. but i fill like blindman in this topic.
KrisPL
krzysztofo@poczta.onet.pl
|
|
|
|
|
I can't come up with a quick concise code sample to answer your question so instead I'm going to run over the basic methodology real quick and then you should be able to transfer it to code.
1) Create a SQL Connection to your database
2) Create an Sql DataAdapter object on that connection. Make sure that you include a proper select all statement (SELECT * FROM Table1)
3) Create a DataSet object.
4) Fill the DataSet using the SqlDataAdapter object.
5) Now read in the xml file into that DataSet into the table Table1
6) Now use the update method (SqlDataAdapter or on the DataSet) to write the information back to the database
Jared
jparsons@jparsons.org
www.prism.gatech.edu/~gte477n
|
|
|
|
|
ok it helps me a bit, i try this before, but i make one mistake on this, i were read xml file to ds hefore i were read it from database (i mean da.fill), so my parts looks like:
XML File:
<records>
<sqlTableName id="1" name="osin" date="2003-01-02" />
<sqlTableName id="2" name="josin" date="2003-01-04" />
</records>
and i have sqlTableName
id, int (PK)
name, varchar(50)
date, datetime
and this code:
SqlConnection conn = new SqlConnection("Server=(local);" +
"Integrated Security=SSPI;" +
"database=UniconDataCenter");//use own database
SqlDataAdapter da = new SqlDataAdapter("select * from sqlTableName",conn);
conn.Open();
da.Fill(ds,"sqlTableName");
ds.ReadXml(Server.MapPath("") + "/test.xml"); //an XML file with data to store in database
//it must be because update command use an insert command
da.InsertCommand = new SqlCommand("INSERT INTO sqlTableName (id, name, date) VALUES(@id, @name, @date)", conn);
da.InsertCommand.Parameters.Add("@id", SqlDbType.Int);
da.InsertCommand.Parameters.Add("@name", SqlDbType.VarChar,50);
da.InsertCommand.Parameters.Add("@date", SqlDbType.DateTime);
da.Update(ds, "sqlTableName");
the problem is: after readxml it get's rows collection, and fill itemArray in the row, but all of it have System.DBNull value, so after ds.Update method it response with error because id is primarykey and can't have null value.
so my next step were to reconfigure xml file, so now it's look like this:
<records>
<sqlTableName>
<id>1</id>
<name>osin</name>
<date>2003-01-04</date>
</sqlTableName>
</records>
and wow, now i have vales in itemsArray ow rows collection, but i still have an error:
System.Data.SqlClient.SqlException: Prepared statement '(@id int,@name varchar(50),@date datetime)INSERT INTO sqlTableNa' expects parameter @id, which was not supplied.
so, any idea
KrisPL
krzysztofo@poczta.onet.pl
|
|
|
|
|
ok, was eat this sh..., the problem was with buid insert command, so i have read some help in different example and there MS says:
use SqlCommandBuilder without this doesn't work, so i've replace my insert command with:
SqlCommandBuilder cmdb = new SqlCommandBuilder(da);
da.InsertCommand =cmdb.GetInsertCommand();
and it's work,
but i have second problem:
i can't fill dataset with xml data stored in file with this format:
<record id="1" name="test" data="2003-01-02" />
it read all fields as null
only this format are good:
<record>
<id>1</id>
<name>test</test>
<data>2003-01-02</data>
</record>
so maybe, somebody know - if it's possible - how to read data as attributes of xml data
KrisPL
krzysztofo@poczta.onet.pl
|
|
|
|
|
I declare a new thread as a class variable
Thread myThread = new Thread(new ThreadStart...);
I call .Start() on the thread and it works fine. However, if I call .Start again on the thread, even after the thread is done executing, an exception is thrown. It seems I have to reinstanciate the thread every time I want to use it. Is this the case or am I missing something?
The graveyards are filled with indispensible men.
|
|
|
|
|
Judah H. wrote:
It seems I have to reinstanciate the thread every time I want to use it. Is this the case or am I missing something?
Yes - I'm pretty sure you have to re-instantiate it. If you don't want to do that, you can create a message queue like the Windows message queue and post messages to it.
|
|
|
|
|
Hmm seems like overkill to me - why have the C# designers forced us to reinstantiate the thread? Provided the thread is stopped or aborted, shouldn't we be able to restart it?
I appreciate the information, though, thanks.
The graveyards are filled with indispensible men.
|
|
|
|
|
No, not necessarily. A thread is created as a temporary execution block for your processor. The Thread class is just a wrapper for that. The documentation states such.
You should look into the ThreadPool and worker threads. The previous poster mentioned to use a similar concept, but why write your own when one already exists with a lot of features. The ThreadPool also limits the number of concurrent threads so your application doesn't hog all the system resources, which is usually a good thing (unless you're attempting real-time execution).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Can someone provide some sample code on how to bind to a checkedlistbox to an arraylist? My situation is I have a checklistbox on a form and a method that returns an arralylist in another class. How can I bind the arraylist in one class to the checkboxlist form in another class?
|
|
|
|
|
To be honest, i'm a bit surprised that CheckedListbox doesn't expose DataSource and others. I'm sure there's a better answer, but at the least you can use it's base class' methods:
ArrayList list = new ArrayList();
list.Add("Hello");
ListBox box = (ListBox)checkedListBox1;
box.DataSource = list;
|
|
|
|
|
Is there any way in C# or other languages to detect the dependent DLLs of an existing non-DotNET DLL (regular DLL)? For i.e. if XXXX.DLL is using AA.DLL and BB.DLL, the last two DLLs are detected by the small piece of code after passing XXXX.DLL name.
Thank you.
Arash Sabet
Computer Engineer
E-mail: afifi@sympatico.ca
|
|
|
|
|
There is no reason to repost your problem.....
You will need to look at dependancy walker or something like that, or read the import table of the dll. Ask in C++ forum, and find out what to do, and the use pinvoke.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Thanks, I was about to reply the same way about the repost.
Since he originally didn't state which DLLs he meant, I replied with regard to dependent assemblies. But in either the case of IL or Win32 modules, this information is not in the import table. It is contained in the assembly manifest and requires that the manifest be read and parsed. If you run depends on most assemblies (barring some of the lower-level BCL assemblies like mscorlib), the only libary in the import table is mscoree, despite whatever externally or internally referenced modules are in the manifest.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I'm trying to develop a system tray application that invokes CTRL-F6 at certain intervals to switch between windows within an application. For testing purposes, I've been trying to send CTRL-F6 to WinWord.exe as a means to iterate through open documents. Have been using FindWindow("OpusApp", null), PostMessage() and SendMessage() with various combinations of
const int WM_KEYDOWN = 0x0100;
const int WM_KEYUP = 0x0101;
const int WM_CHAR = 0x0102;
oonst int WM_SYSCOMMAND = 0x112;
const int SC_NEXTWINDOW = 0xF040;
const int VK_CTRL = 0x0011;
const int VK_F6 = 0x0075;
I've had no successs. Anyone's help with this would be greatly appreciated.
casey
|
|
|
|
|
You could always use SendKeys.Send (see docs for formatting) to send keyboard events to the open application. Just make sure that Word's active.
Are you getting a return value (IntPtr ) back from FindWindow ?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks Heath...
I considered SendKeys.Send but wasn't sure how to get the active window. So I used the IntPtr from FindWindow as handle for SendMessage and PostMessage since they don't seem to require the window to be active. Maybe I need to reference a different ClassName/Window Handle, or missing the whole idea of this.
If SendKeys.Send is used, how do I determine active application windows before invoking CTRL-F6? Again, testing with multiple open, Word documents.
casey
|
|
|
|
|
If you can't be sure, it's best to use PostMessage (keyboard input is usually handled by message pump). Are you getting a return value for the IntPtr return from FindWindow ? If so, use Spy++ (should be installed with VS.NET if you installed the Platform SDK) to see if that matches the window handle of Word (use the Windows finder (like a crosshair)).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
If you can't be sure, it's best to use PostMessage (keyboard input is usually handled by message pump).
I agree - why not send the messages directly to the window, rather than relying on it being active?
|
|
|
|
|
IntPtr doc1 = FindWindow("OpusApp", "Document1 - Microsoft Word");
IntPtr doc2 = FindWindow("OpusApp", "Document2 - Microsoft Word");
return correct window handles verified with Spy++. Spy++ message logging also shows the Post for the following but no document window action is initiated.
PostMessage(doc1, WM_KEYDOWN, VK_CONTROL, 0)
PostMessage(doc1, WM_KEYDOWN, VK_F6, 0)
PostMessage(doc1, WM_KEYUP, VK_CONTROL, 0)
PostMessage(doc1, WM_KEYUP, VK_F6, 0)
If I manually invoke CTRL-F6 to switch between documents, Spy++ doesn't show KEYDOWN/UP commands but does show WM_ACTIVATE, WM_ACTIVATEAPP among other window refresh commands. Changed my code to invoke the following in a loop and the document windows toggle as if using CTRL-F6. It works.
PostMessage(doc1, WM_ACTIVATE, 0x1, 0x056C)
PostMessage(doc2, WM_ACTIVATE, 0x1, 0x056C)
It seems manually depressing CTRL-F6 is handled by a process or other window handle, which send WM_ACTIVATE to the window handles I'm referencing. I'll continue to use WM_ACTIVATE unless something else is suggested.
casey
|
|
|
|
|
Glad you got it to work! The only thing that makes me curious is why the keyboard messages didn't work. When messages are passed via PostMessage , they go to the application pump. In that pump (loop), TranslateMessage is called on the message to translate virtual key codes. Word must have an app pump associated with some other handle, but I can't fathom how that's even possible or why.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi,
I am trying to make some c# in memory data to look like a file to windows.
The functionality i would like to implement is
- open the "file" with the registered application for this filetype (like winword for .doc files)
- capture modifications after saving the data from the application.
Is there a smarter way than writing the data into a tempfile ? And if a tempfile is the only solution - how is it possible to find out if the application has finished modifying the data ?
As you might guess, I am more familiar with Un*x variants, where a pipe would have been the solution.
many thanks in advance
|
|
|
|
|
What you're talking about is monikers and custom views, which is all part of shell programming and probably not worth it (dozens of interfaces are required in multiple objects as well as a lot of registry handling). For starters, you can look up IMoniker in the PSDK and the entire "User Interface / Shell Programming" section in the MSDN Library.
One other option is to look into file fragment programming. I haven't seen these used in a long time. An example would be dragging and dropping a block of text from a Word document to a folder. It creates a fragment (requires monikers). Double-clicking that fragment would open your app (if not already open, which again reqiures monikers) and load the referenced stream (or other STG). If you wanted to custom that scrap icon, you could add an icon handler which is another shell extension.
I can't really think of an easier way to do it than what would be possible in *nix. You're talking of block devices, right?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Depending on what you want to do, you could use a memory mapped file (a solution also available on *nix).
All POSIX features like pipes are also available on Windows NT and later and you can use them easily. Pipes can be implemented using the Console class. You can even start another application (like the system() function call) and redirect its std input and output to streams (which can be, e.g., a memory stream).
The only *nix thing that's not so easy to emulate is fork().
HTH.
Trying to make bits uncopyable is like trying to make water not wet.
-- Bruce Schneier
By the way, dog_spawn isn't a nickname - it is my name with an underscore instead of a space. -- dog_spawn
|
|
|
|
|
Is there any way in C# or other languages to detect the dependents DLLs of an existing DLL? For i.e. if XXXX.DLL is using AA.DLL and BB.DLL, the last two DLLs are detected by the small piece of code after passing XXXX.DLL name.
Thank you.
Arash Sabet
Computer Engineer
E-mail: afifi@sympatico.ca
|
|
|
|
|