Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Newbie needs help: treeview, datareader, and a function
Who's asking this question:
1. A newbie.
2. This is my second C# program.
3. I've done VB programming in the past.
4. I'm rusty on OOP - usually where I trip up.

Here is what I've got:
1. A form with treeview.
2. A database with a table.

Here is what I want to do:
1. Populate the treeview with each record in the table.

What you'll notice:
1. Why use a treeview?  Future functionality.  I plan to have "sub
projects".
2. But for now I want to have a node per record.

My problem:
1. If the fillTree function is a void then when I call in in my main(),
I get "an object reference is required for the

nonstatic field, method or property...".
2. However, if I make it static void fillTree(), then I get an error
one the line "projectTree.Nodes..." where it says -

"...projectTree' denotes a field where a class was expected".

Help!


My function:

I use the line fillTree(); in Main() to call the function below.

void fillTree()

// Binds the tree view to data
{
int nRows = 0;

string conStr = @"server=myserv;" +
"Integrated Security=true;" +
"database=GroupProjectTracker";

SqlConnection Conn = new SqlConnection(conStr);

try
{
Conn.Open();
string SQL = "SELECT * FROM tblProjects WHERE projectStatus =
'Open'";
SqlCommand sqlComm= new SqlCommand(SQL, Conn);
SqlDataReader sqlReader = sqlComm.ExecuteReader();

while (sqlReader.Read())
{

projectTree.Nodes.Add(sqlReader[1]);


}
}
catch (Exception ex)
{
MessageBox.Show ("Error connecting to database: " + ex.Message);
Conn.Close();
}
finally
{
Conn.Close();
}


Report this thread to moderator Post Follow-up to this message
Old Post
techprot-google04
11-27-04 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

C# archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:42 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.