Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VS2005 TreeView Problem 1

Status
Not open for further replies.

ryanchk

MIS
Jun 17, 2005
1
0
0
US
when tyring to hard-code databinding to a tree view in VS2005, the following code says that there is no definition for 'RunQuery' in the current context.
void PopulateCategories(TreeNode node)
{
SqlCommand sqlQuery = new
SqlCommand("Select * From Categories");
DataSet ResultSet;
ResultSet = RunQuery(sqlQuery);
if (ResultSet.Tables.Count > 0)
{
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
TreeNode NewNode = new
TreeNode(row["CategoryName"].ToString(),
row["CategoryID"].ToString());
NewNode.PopulateOnDemand = true;
NewNode.SelectAction = TreeNodeSelectAction.Expand;
node.ChildNodes.Add(NewNode);
}
}
}

is this a VS2005 Beta bug or is ti fixable?

 
There isn't a built in "RunQuery" method. I'm guessing you're looking at MS help?? You have to define that method yourself.

A quick search I found this example in the treenode help:

DataSet RunQuery(String QueryString)
{

// Declare the connection string. This example uses Microsoft SQL Server
// and connects to the Northwind sample database.
String ConnectionString = "server=localhost;database=NorthWind;Integrated Security=SSPI";

SqlConnection DBConnection = new SqlConnection(ConnectionString);
SqlDataAdapter DBAdapter;
DataSet ResultsDataSet = new DataSet();

try
{

// Run the query and create a DataSet.
DBAdapter = new SqlDataAdapter(QueryString, DBConnection);
DBAdapter.Fill(ResultsDataSet);

// Close the database connection.
DBConnection.Close();

}
catch(Exception ex)
{

// Close the database connection if it is still open.
if(DBConnection.State == ConnectionState.Open)
{
DBConnection.Close();
}

Message.Text = "Unable to connect to the database.";

}

return ResultsDataSet;

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top