|
Here is a hint, XPath. Now go away and do as Luc has suggested.
only two letters away from being an asset
|
|
|
|
|
|
What I would like to do is instead of manually parsing for each table and row. I would like to learn how to do a foreach to dynamically find each table and each row in a database. Here is what I curently have, All I am asking is how to use the foreach command to do this.
1) How would you say:
foreach(table in database)
then how would you say
foreach(row in table)
New experimental project I am playing with. I will post back when I find something. Just thought I would ask.
string sConnectString = "Driver={QODBC Driver for QuickBooks};DFQ=C:\\Quickbooks\\sample_company_file.qbw;OpenMode=M;OLE DB Services=-2;";
string sSQL = "SELECT Name FROM Employee";
OdbcConnection cn;
OdbcCommand cmd;
cn = new OdbcConnection(sConnectString);
cmd =new OdbcCommand(sSQL,cn);
try
{
cn.Open();
MessageBox.Show("open");
OdbcDataReader dr = cmd.ExecuteReader();
dr.GetSchemaTable().
MessageBox.Show(dr.GetSchemaTable().TableName);
}
catch (OdbcException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cn.Close();
}
|
|
|
|
|
Hi,
1.
obviously you get all rows in a table by selecting everything as in "SELECT * FROM tablename", so just skip the WHERE clause.
2.
how you get information on the tables themselves probably depends on the database; in MySQL it simply is "SHOW TABLES"
Look in the documentation for your database!
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
JollyMansArt wrote: 1) How would you say:
foreach(table in database)
then how would you say
foreach(row in table)
foreach is not a realy usable construct for examining database tables, I would normally use
reader = sqlCmd.ExecuteReader();
while (reader.Read())
{
...
}
Think about it: if you were dealing with a file, you would say:
string[] lines = inFile.ReadAllLines();
foreach(string s in lines)
{
...
}
rather than trying:
foreach(LineOfText line in inFile)
{
...
}
You can't use foreach for the columns, either - there isn't an Items collection - but even if you could, it really wouldn't be too helpfull:
foreach(var v in reader.Items)
{
... Workout what type it is and what to do with it...
}
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hi
I have a datagridview (in a windows application) which its data comes from executing a StoredProcedure. This SP joins two tables and derives the data needed.
what is the role of dataview in inserting a new row and updating dgv rows (and validating them) and delete rows?
Can a dataview save these changes? and somehow apply them to the DB all toghether?
I've done these before by applying every change to the DB and refill the dgv after that. But I think it's not the right way. and I didn't find a full sample that can guide me through this.
next, to search in dgv and find the word that user wants, and somehow specify the found results (for example bolding the found words) in dgv. how it should be done? by dataview?
please help
|
|
|
|
|
Hi,
I have an xml file with about 50, 000 records.
Each record has a lot of hierarchy i.e. elements, sub-elements...
I would like to be able to do the following i.e.
1-search for a value in one of the elements
2-delete a row i.e. a sub-element in an element
3-modify a row
What is the best way to start this with?
Should I use xmlDocument?
Thanks
|
|
|
|
|
I would investigate LINQToXML. From my experience it is far easier than XmlDocument.
Just my 2 cents!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I agree with Heny, if you're using .NET 3.5 (or possibly 4.0) then definately Linq to XML. There's plenty of tutorials around. This will do everything you need and more, enabling you to query your XML very much like a database.
|
|
|
|
|
And how about updates, deletes and inserts into the xml file with 50, 000 records?
will linq do this also?
Thanks
|
|
|
|
|
No, Linq to XML is limited to 49,999 records.
With this much data it would be better to use a database.
only two letters away from being an asset
|
|
|
|
|
How can I use a database for this?
There are so many hierarchies i.e. elements, subelemenst, etc...
|
|
|
|
|
Yes it will - but the downside is it will be slow compared to a database. There is nothing that can be done with XML that can't be done with a well structured relational database, it can just require a little more thought and be somewhat more intricate to configure the database initially, but once done it is normally the best way to go.
Try it on a large but simpler data structure first and compare the speeds - at least this way you'll have the fun of learnining LINQ which can be very useful even if you decide to drop it.
|
|
|
|
|
Did this a long time ago with C++ and XML
XML timing[^]
only two letters away from being an asset
|
|
|
|
|
Mark Nischalke wrote: No, Linq to XML is limited to 49,999 records.
I wasn't aware of that. Any chance of a link, so that I can check out other showstoppers.
Mark Nischalke wrote: With this much data it would be better to use a database.
This is absolutely true and even if the data only has 50,000 records now, the OP is talking about inserts etc. so that there are likely to be more in future.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
How do I do this in database?
|
|
|
|
|
arkiboys wrote: How do I do this in database
The conversion to a database will be time consuming and possibly difficult, depends on the structure of your xml file, but will repay the effort many times over as time goes by.
I am not aware of any tools that can automate the process entirely, although if you create the database and tables manually you can use the bulk loading methods of SQL Server to load the data.
You can also do a sort of half-way-house thing. Look at the DataSet.ReadXml , DataSet.ReadXmlSchema methods and the associated Write ones.
Whether any of this is possible or practical depends mostly on the structure of your xml.
The earlier comments about a limit for LINQToXML was a joke so that avenue is still open to you.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I am now learning linq.
Many thanks
|
|
|
|
|
Henry Minute wrote: I wasn't aware of that.
I think he has his sarcasm hat on tonight
|
|
|
|
|
At least someone recognized it
only two letters away from being an asset
|
|
|
|
|
I sort of half thought so because of the emoticon he used and I googled before asking for a link. I am however very gullible and you can never be sure.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
arkiboys wrote: Should I use xmlDocument?
I would; I don't do Linq.
|
|
|
|
|
Im creating a program which is signed. And ive referenced a usercontrol that I have made. But when I build it says:
Error 1 Assembly generation failed -- Referenced assembly 'dll name here' does not have a strong name
But surely if I signed the dll then the strong name file wont get included in the dll making it pointless?
So how do I fix this? Keeping in mind I need to be able to install this on other pc's.
Thanks
Strive to be humble enough to take advice, and confident enough to do something about it.
|
|
|
|
|
You're right, Microsoft has just strung us all along for the last eight years with assembly signing and strong names, all to find out it is pointless.
Strong Names Explained[^]
only two letters away from being an asset
|
|
|
|
|
Hi if you add strong name for one dll, then you should use strong name for all the places, where you use that dll. for example i have added strong name for one class library project and i need to use strong name where i use (refer) the class also...
|
|
|
|