|
Then you're in teh wrong place. Go buy a book on XML and read it for starters.
only two letters away from being an asset
|
|
|
|
|
Mark Nischalke wrote: Then you're in teh wrong place. Go buy a book on XML and read it for starters.
Almost any XML book I know of is not on specific topic like What should I do with XML in my .net C#, program or something... beside not much choice on that topic here... I'll look around on-line instead I guess...
|
|
|
|
|
TrooperIronMan wrote: What should I do with XML in my .net C#, program
After supposedly reading online resources such as CP and MSDN as well as books and you still can’t answer this question it's time to chose a new career.
TrooperIronMan wrote: Almost any XML book I know of is not on specific topic like What should I do with XML in my .net C#,
If you find the book that tell you what to do for your specific project you'd better keep it secret because half the posters on CP will be bombarding your inbox wanting to know where to get a copy.
Books, magazines, articles, etc. are not going to tell you what to do for your own little world, you have to do something creative, like actually think for yourself.
only two letters away from being an asset
|
|
|
|
|
Mark Nischalke wrote:
If you find the book that tell you what to do for your specific project
I though more likely about best practice...
Mark Nischalke wrote: After supposedly reading online resources such as CP and MSDN
Hard to read much on 56k that brake up line every minute or so that is why I hoped someone do have link for more specific article or sections...
Mark Nischalke wrote: it's time to chose a new career.
nah... too late for that... now...
|
|
|
|
|
The best advice is, don't use it until you need it.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I do have one scenario I can think about right now that require something like xml or config file... but would like to try xml on it...
For now all I'm doing is learning new tech... so i just explore...
|
|
|
|
|
You can do just about anything you want with an XML file, just as you have listed.
I personally use them for small databases or settings. For example, I made an XML file containing all the countries in the world. I use this in my applications to populate a Countries ComboBox or DropDownList
Live in fragments no longer. Only connect.
|
|
|
|
|
bluewavestrider wrote: For example, I made an XML file containing all the countries in the world. I use this in my applications to populate a Countries ComboBox or DropDownList
there you go, can you supply some source code, I though about same thing have some drop down lists that I would like to be able to save to XML since user can add some data to them... but it get saved in plain text file... not so cool solution...
|
|
|
|
|
You can use XML for anything that you want. It's just a flexible data format, it has no specific purpose.
XHTML is XML. SOAP uses XML. AJAX uses XML. RSS uses XML. It's everywhere...
---
Year happy = new Year(2007);
|
|
|
|
|
I know but I still need some examples of good practice... and how to do it... so... anyone
some code please
|
|
|
|
|
Your question can't be answered. What code are you hoping for ? The net abounds with examples of uses of XML, for example, config files, or data files. But, your question is too open ended. The best practice is, if you need to store heirarchical data, or data whose layout may change, XML is worth considering.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
OK, this is one of scenarios I'm currently working on:
there is combo box I enabled user to add some data in it, I want to save all that data at program close, and to load same data when program start (it's list of cities btw)
I want to save last used file path and load same file at program start up if user confirm it want to continue to work on same data.
I want to output some text boxes, datetime pickers, etc at and of work so same data can be loaded at start up if user want so... basicly creating data set in xml...
So those are things I'm trying to achieve I can use textual files (and I do use them right now), but I believe with XML it would be easier to manipulate data and more flexible?
So any help now?
|
|
|
|
|
Sorry if title bit abrupt. I have an Access Database, in this database are two tables, one is a table of teams and the other a table of players. My table of teams contains 11 index numbers (1 for each player).
My program currently loads all the teams from the database, while loading each teams, it search's the other table for the players details using the index number.
I know this will query the database 11 times for each team. This seems to really slow down the program to an unmanagable speed.
What is the best and fastest way to talk to an access database and am i going about it the right way? A sample of how I am currently querying the database is below. Thanks
string strQuery = "SELECT * FROM t_DT_Teams;<br />
OleDbCommand dbsCommand = new OleDbCommand(strQuery, dbsConnection); <br />
OleDbDataAdapter dbsAdapter = new OleDbDataAdapter();<br />
dbsAdapter.SelectCommand = dbsCommand;<br />
<br />
DataSet dbsDataSet = new DataSet();<br />
dbsAdapter.Fill(dbsDataSet, "t_DT_Teams");<br />
DataTable dbsDataTable = dbsDataSet.Tables["t_DT_Teams"];<br />
<br />
// i then loop through each team and do roughly the same to find a player<br />
<br />
dbsConnection.Close
|
|
|
|
|
Instead of using * you should try to list the column names directly. I can't tell you what the exact performance hit is, but I know you should always try to list the columns you want.
I don't know if there is any better way to do this then how you are currently doing it. Do you use the dataset, you can set the datatable in place of the dataset if you don't need it. Also, try using the using(connectionType connection = new connetiontype(connectionstring){}. You don't have to close your connection when you are done as this will do it for you.
Wish I could help More.
|
|
|
|
|
avanwieren wrote: You don't have to close your connection when you are done as this will do it for you.
Very bad advice. You should always close the connection because it immediately frees up the resources on the database so it can be accessed by another application, or even a different part of the same application.
If you don't call close you are at the mercy of the garbage collector as to when the connection is finally closed. Each time you open a connection you'll need a new one as the previous one isn't closed yet. This might cause the application to fail if the database is too stretched to open a new connection. The cause won't be immediately apparent because the cause of the error isn't at the point the connection is opened, it is at the point the connection should have been closed, but wasn't.
|
|
|
|
|
Actually,
when you hit the final end bracket of the using statement,a dispose call is made closing and disposing the connection. Using the using statement does the exact same thing as opening and then closing a connection manually, it just is way easier to read. You should also do the same thing with the command object as it is also IDisposable type.
using (SqlConnection connection = new SqlConnection(connectionString))
{
Do some thing with the database here!
}
Is the same as
connection.open();
connection.close();
Pardon the berevety.\
Aaron
|
|
|
|
|
avanwieren wrote: when you hit the final end bracket of the using statement
On re-reading your original post, I see that I'd missed that you were suggesing using a using block. Now that you've shown this formatted version is it much easier to understand. I should have been more careful in reading your post.
|
|
|
|
|
I agree with you on the importance of closing connections and understand the misgivings about what I originally wrote as I was not very clear in some ways. I especially love using the using block as it is much easier to read and really helps separate the code into a more manageable chunk. Where I work our code base was/is in VB6, tended to have alot of open connections that never got closed and had provide numerous nightmares performance wise.
I should have put the using statement into a code bracket, easy to misinterpret.
No biggie.
|
|
|
|
|
I would use column names instead of the *, but there are only 5 fields and I need them all.
On the connection thing, i tried to be clever by opening the connection at the begining and using the same connection to do everything, I then close it at the end when I have finished.
Surely c# talking to an access database can't be this slow! VB6 was much faster than this and is putting c# to shame at the moment. It is currently taking between 30-60 seconds do get info from a database in c# where vb6 seemed to do it instantly.
|
|
|
|
|
Do you need a dataset or will a datatable work? IHO datasets tend to be overkill when all you need is a single datatable. The slow down could also be from the fact that vb6 is unmanaged code and does not require compilation into MSIL where as the .Net(not just c#) tends to run slower initially because it is managed code. You could create a test harness and run this process a couple of times to see if it is just initially slower.
Without knowing too much of your code, but from the description the other thing I would try would be to get all the tables you need, close the connection, then do your select statement on the datatable for what you want. You then can work with just the set of data at that time that is selected by the select statement.
Just some thoughts.
|
|
|
|
|
Thanks for your reply .
No I dont need a dataset, I just thought that is what I needed to do to get it to work. Didnt know you could just use a datatable, although I have just tried this and it didnt help with the speed.
The idea of loading everything then querying sounds good, but how do you query a DataTable? I've never done that before.
|
|
|
|
|
Another question. Are you just reading the data from the database or are you altering the data? If you are just reading the data you could use the datareader which is much faster but only processes in a forward direction.
In regards to the select statement it is a method of the DataTable. The select statement takes an expression that is like value=1. Your code would look somehting like this:
DataTable dbsDataTable_= new DataTable("DT_Teams");
string strQuery = "SELECT * FROM t_DT_Teams;
string connectionstring = "YourConnectionString";
using(OleDbConnection connection = new OleDbConnection(connectionString)
{
OleDbCommand dbsCommand = connection.CreateCommand();
dbsCommand.CommandText = strQuery;
OleDbDataAdapter dbsAdapter = new OleDbDataAdapter(dbsCommand);
dbsAdapter.Fill(dbsDataTable);
}
From here you can work with the datatable and query the results:
DataRow[] result;
string expression= "column (= > <)value)";
result = dbsDataTable.Select(expression);
You then can work with the datarows with a foreach clause to process or retrieve your results. The best part of this is that you only access the database and get the data you want once, then you can select, sort, add columns and rows and compute your data disconnected from the database. The down side is that datatables are stored in memory.
Let me know if this works.
|
|
|
|
|
At the moment I am just reading from the database. I will need to write to it later on but not during this part of the program.
I was originally using a datareader but because i look at the team table and then search the players table, it wouldnt let me open more than one datareader at a time and wanted me to close any existing ones, which I couldnt do because I needed to go back to it.
when you do a select on a datatable, can you specify which column you want to search in? Are the expressions the same as sqlquerys?
|
|
|
|
|
deanpugh wrote:
I was originally using a datareader but because i look at the team table and then search the players table, it wouldnt let me open more than one datareader at a time and wanted me to close any existing ones, which I couldnt do because I needed to go back to it.
There are ways to save the results and work with them, but I am not as familiar with the DataReader as the DataAdapters. It is always good practice to close your connections as soon as possible, this is where the disconnected datatables are really good.
deanpugh wrote: when you do a select on a datatable, can you specify which column you want to search in? Are the expressions the same as sqlquerys?
In most ways yes. The expression is very similar to a where clause.
A good resource on what all can be done:
http://msdn2.microsoft.com/en-us/library/system.data.datatable.select.aspx
http://msdn2.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx
These should give you good references regarding the select itself as well as the expression parameters.
Hope this helps.
|
|
|
|
|
Thanks. I will give that a go and see if it solves my problem and will post back when I can.
|
|
|
|