Configurationmanager Member
Provides access to the client application configuration file. This class cannot be inherited. Private dataset runquery (sqlcommand sqlquery)
{
String connectionstring =
Configurationmanager. connectionstrings
["Northwindconnectionstring"]. connectionstring;
Sqlconnection dbconnection =
New sqlconnection (connectionstring );
Sqldataadapter dbadapter = new sqldataadapter ();
Dbadapter. selectcommand = sqlquery;
Sqlquery. Connection = dbconnection;
Dataset resultsdataset = new dataset ();
Try
{
Dbadapter. Fill (resultsdataset );
}
Catch
{
Labelstatus. Text = "unable to connect to SQL Server .";
}
Return resultsdataset;
}
// Get connectionstrings.
Static void getconnectionstrings ()
{
// Get the connectionstrings.
Connectionstringsettingscollection connectionstrings =
Configurationmanager. connectionstrings;
// Get the collection enumerator.
Ienumerator connectionstringsenum =
Connectionstrings. getenumerator ();
// Loop through the collection and
// Display the connectionstrings key, value pairs.
Int I = 0;
Console. writeline ("connection strings .");
While (connectionstringsenum. movenext ())
{
String name = connectionstrings [I]. Name;
Console. writeline ("Name: {0} value: {1 }",
Name, connectionstrings [name]);
I + = 1;
}
}