Hello, I'm fairly new to the C# world. What am I saying? I'm pretty new to coding all around and I've ran into a problem I have had to luck figuring out. So...
Before you ask, yes I have looked threw articles on the site. But none of them really help me. It is very hard to understand uncommented code at my skill level so it really does no good to me.
My first C# application is a simple RSS reader. I have most of the stuff done for it besides the TreeView. I cannot seem to figure out how to get this TreeView to grab data from my database and then display it in a certain way.
Ok so I have three folders in my database: Folders, Feeds, and NewsItems. The folders in the tree view will call the database table Folders, the rss channels/feed will call data from the Feeds table and finally the news items will call data from the NewsItems table.
How would I go about doing this? I have predefined values in all tables in the database, I'm not worried about adding new stuff to it yet and have it update. I just need to get the view to work.
You can read data from the database using the System.Data.SqlClient.DataReader class to read data from your database. Once you have that data, you can create tree nodes from that data, then add those nodes to the treeview. Here's some idea of what this would look like:
SqlConnection connection = new SqlConnection("your connection string goes here");
SqlCommand myCommand = new SqlCommand("Select * from MyTable");
myCommand.Connection = connection;
SqlDataReader reader = myCommand.ExecuteReader();
// This will pull a string from the first column in the MyTablestring nodeText = reader.GetString(0);
// This will create a tree node and add it to the tree view.
TreeNode node = new TreeNode(nodeText);
Thanks for the help. I've ran into another problem while editing somethings. In order to use this it said to open the database, so I used:
But it spits out an exception:
System.Data.SqlClient.SqlException was unhandled<br />
Message="An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
I don't understand how it is a remote connection if the database is the SQLServer that comes with C# Express 2005. Any ideas?
Oh, yes, you'll need to open a connection to SQL. This error occurs when SQL either isn't configured to allow connections to it from remote machines, or your connection string is invalid. Are you sure that connection string works? Try connecting to the database from, say, Sql Management Studio, or some other tool with that connection string to verify your connection string works.
p.s. judging by the error, named pipes might not work in this scenario. Try TCP.
When it loads it imediatly takes up 9MB, now i know thats not alot, but where is it going? When the app loads it displays an empty listbox with 4 colums, two combo boxes with 10 items in, 5 buttons, and a text box.
It also creates 2 bools and a ListViewItem array, all empty. (The array is not given a size, just defined)
It does no processing, doesn't load any files, doesn't connect to the internet, until the user does something.
So err, why is it using so much and how do i fix it?
That's the way .NET works. It allocates that "much" memory without actualy needing it. Reason is performance. Allocating one big block is more efficient then allocate many little blocks of memory. When later you need memory, "allocating" is as fast as changing one pointer. IIRC .NET does release this extra memory when OS is getting low on memory. No big deal in 99% of cases.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
We are using Visual Studio .NET 2003 ,C# and MS SQL SERVER 2000.
Ours is a Web Application. Now i need to develop some reporting application with which our power users or executives should be able to pull data and make decisions.
can I integrate that with my web application?
What are options here? why?
My visual Studio.net 2003 has crystal reports but asking me for registration. do i have buy a different license for it?
Is crystal reports and Business objects same? and what version should i select?
Any help on this would be really appreciated.
Could anyone tell me the best book available for:
2. C# 2.0
2. .NET Framework 2.0
I am new to .NET and C# (and programming). I have been working on VB.NET 2003 for the past 6 months and would like to learn more about .NET 2.0, OOPS, and .NET Framework 2.0. Any information that you guys would like to share would be appreciated.
Professional C# 2005 is not a professional level book. Sure it isn't an intro to programming but I am looking for more in books with the professional title.
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
Professional C# 2005 is not a professional level book.
I don't understand that statement. For example when I used the Remoting Chapter, I found the information was complete and presented in a logical fashion. What do you mean by "not a professional level"?
Implies years of industry experience and the ability to search on the web and read API references. A book with the title Professional should understand that focus on applications of the new technologies in difficult and new ways which would expose a professional to A) Solid reference to advanced topics and B) Provide exposure to methodology
While definately not intro to programming the book is an intro to C#.
I think B is critical because without a second, third, fourth voice everything becomes an echo chamber. Perspective from experience is crucial in a professional level book.
Not sure what all that means but if you read the back cover synopsis you would not expect to see any echo chamber stuff in there.
Ennis Ray Lynch, Jr. wrote:
As for A your definition of coverage and advanced topics may be different from mine.
Well I am not comparing this to something like Advanced Windows (Richter). The back cover synopsis of the book it does not claim to be anything like that. The only part of the back cover I disagree with is "so that you can begin programming like an expert right away", no book should claim that. In this case it covered topics like Remoting and EnterpriseServices which I used and found them to be "exactly" what I needed. First a simplified discussion and example leading to more complex aspects of the topic resulting in coverage of a variety of implementation options. Please note, that does not mean "in depth". The synopsis also says "help you gain a well rounded understanding", which I believe is accurate.
First I want to congratulate you on choosing to travel the path of OOP instead of reading fat books that tell you how not why. I like Robert Martin however his C# book is not that overwhelming but check out his web site www.objectmentors.com and when you have tired of that try www.oodesign.com.
I like Apress books for C# I used Pro C# 2005 and the .NET 2.0 Platform, Third Edition which was not as good as his 2003 Book but it is a pretty solid reference.
Foundations of Object-Oriented Programming Using .NET 2.0 Patterns by Christian Gross is a great book on OOP and Patterns you may want to look at I have found it quite good but it is complex. Beyond that may I suggest some O'Reilly books on the framework and c#.
Thanks alot for your reply, thanks to others too who took time to reply to my query.
In our part of the place, its easier to get a Wrox book rather than Apress or others, so I guess I'd get a Professional C# 2005 from Wrox and also use Internet as a resource.
But I always feel that the way we code in my company (it has a strength of 6 .NET developers) is of no good when I see code and articles posted by members of CodeProject. I would like to ask one thing, where can a person who is new to programming learn good coding standards, how can I know if the code I have written is good, how can I ensure that my piece of code doesn't waste memory.
Only thing commonly told here to improve performance of out application is to Dispose all objects we create and use more of .NET Classes. Is there any way that a person can get to know such things?
I hear you when it comes to standards. Programmers are probably the most opinionated group of people on earth I think this is because they are usually pretty bright and tend to think for themselves. The down side to this is trying to get a review without to much opinion such as coding standards.
In my humble opinion coding standards should be driven by need more than conceptual designs. My coding has changed because I truly hate producing code that I have to support or is riddled with bugs. Here is a list of stupid things I have done that do not work. Methods that are long and hold duplicate code (bad bad bad), inadequate use of constructors (initialize all member variables), a class that handles too much work (makes the program fragile) and my favorite classes that have dependencies on other classes to do their work.
I like the work from Robert Martin and Martin Fowler both of which have great web sites that provide in depth ways to solve my bad habits. I suggest that you start there then just review as much code as you can look for the why not the how in the design.
As a side note one of the things that our team has instigated is the practice of each team member presenting an OO Design principle or Pattern every year. What this will do is provide an outlet for research into the craft that we practice and creates a healthy learning environment. There is no magic book or web site you just have to dig deep and get very good at what you do and it takes time.
I would like to offer this insight however and I will paraphrase from a post I read here on CP. The languages we use are not for the benefit of the compiler they are structured the way they are for the humans. The code is written into IL in a much different format than your design. Use the OOD to make what you do better that is what it is for the processor could care less about OO so keep your eye on the prize stable maintenance free software.
Best of luck I look forward to hearing of you progress.
Last Visit: 31-Dec-99 18:00 Last Update: 1-Oct-23 15:58