I have made a context menu switch and a treeview! The context menu role is to delete the node on right click (from the delete button in menu of course) but the problem is that selectednode.text is always null! I want to get the text of the selected node and search in database to delete it from database! Here is the code
At the point of the exception the value of i is not valid for your array labels, probably it's too high. Place a debug-breakpoint on the line of the for-loop, run your program in debug mode, step through the iterations of the for-loop and you will recognize what's going wrong.
and the error is: Value cannot be null.Parameter name: device
The is the Code...
publicpartialclass Form1 : Form
privatevoid button1_Click(object sender, EventArgs e)
path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User);
using (RasPhoneBook pbk = new RasPhoneBook())
RasEntry entry = RasEntry.CreateBroadbandEntry("osama",RasDevice.GetDeviceByName("(PPPoE Osama)",RasDeviceType.PPPoE));
// Configure any options for your entry here via entry.Options
using (RasDialer dialer = new RasDialer())
dialer.EntryName = "Your Entry";
dialer.PhoneBookPath = path;
dialer.Credentials = new System.Net.NetworkCredential("User", "Password");
If there is another way please tell me how.
To Be Or Not To Be
But personally, I wouldn't do that - it encourages you to maintain a connection for teh life of the application which is a pretty poor practice. It also means that you only get one connection, so some operations are not possible - any INSERT or UPDATE while processing a SqlDataReader for example. I'd create the connections as I need them, inside a using block so that they are closed and disposed when I'm done.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
You never should create a variable for database connection in a global scope. It would consume resources even where you do not need a database connection. Such as, when user is not authenticated, and you're showing him a view (or a dialog box) to tell him that he cannot connect to the database for query purposes, but in the background database would be connected already. Which won't be a good usage of your logic or resources.
It would be better to create this variable, inside the function where you need it. Connection pooling would take care of the underlying connection maintenance for your application so that you won't get a delay for connecting to the database server.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~