Simple Windows Forms Application


Nov 20, 2012

Currently working on a fairly simple forms application. Since I am a complete newbie, I can't figure out even simple stuff. I would appreciate any help in this regard. This is what I intend to do:

  1. A small application that pings a list of servers.
  2. The list is stored in a Access mdb file.
  3. When the application pings the PC's in a loop, it looks for any PC that's offline.
  4. If counts the PC's that are offline and those which are online and reflects that count separately onto two labels somewhere on the form.
  5. Plus, it should log the event if it sees that any PC was unreachable. The logging should be done in that AccessDB file, but in a separate table. Logging the time and the PC name is enough for this.
  6. There could be a button on the form, from where I can pull the logs to a grid of some sort.
  7. On every offline event, the application should email the name of the offline PC, to a particular list of recipients. This list is also present in a separate table in the AccessDB file.
  8. I plan to embed crystal report in it. Which can generate a report on demand, according to the filters that I set in the report. i.e. PCName, Date etc.

I know my wish list is huge. But, I learn fast. I require some guidance and I can code along the way. Considering that I am a total noob at .Net, please mention the solution in a layman's terms.

Note: I am coding this on "Visual Studio .Net 2012"

Thanks & Regards


Jul 1, 2005
UK North East
Hi Prof,

Firstly you're going to need to set-up a connection to your MS Access database. To do this you can either use an BindingSource to your form, and set-up the DataSource property for this to point to your access database then cycle through the data using this object. Or, alternatively, you can do this all through code (far more readable!).

A quick and simple demo of how to ping a server using code:

1. Add a textbox and button to the form.
2. Double-click the button to go to the code behind.
3. Add the followig code to the Button1_Click handler...
Visual Basic:
Dim ping As New System.Net.NetworkInformation.Ping()
If ping.Send(TextBox1.Text).Status = Net.NetworkInformation.IPStatus.Success Then
	MessageBox.Show("The server " & TextBox1.Text & " exists.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
If you want to iterate through a list of database servers then you could try this...
Visual Basic:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
	'Define the connection to the database - you'll need to provide your own connection string here...
	Dim conn As New OleDbConnection("accessdbconnectionstring")
	'Define the SQL to read the information from the database...
	Dim sql As String = "SELECT servername FROM serverlist "
	'Define a command object to execute the read...
	Dim command As New OleDbCommand(sql, conn)
	'Open the database connection...
	'Define and execute your reader...
	Dim reader As OleDbDataReader = command.ExecuteReader()
	'Loop through the data while it can be read...
	Do While reader.Read()
		'Define a ping object...
		Dim ping As New System.Net.NetworkInformation.Ping()
		'Test the ping to see if it was successful...
		If ping.Send(reader("servername").ToString()).Status = Net.NetworkInformation.IPStatus.Success Then
			TextBox1.Text = TextBox1.Text & reader("servername").ToString() & " successful" & vbCrLf
		End If
	'Close and tidy-up...
	reader = Nothing
	conn = Nothing
End Sub

This is a very basic form for what you are looking for. Hope this helps.

Kind regards,


Mar 28, 2008
A simple connection si follwoing... if you want to know more

string connetionString = null;
SqlConnection connection ;
SqlCommand command ;
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds = new DataSet();
int i = 0;
string sql = null;

connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password";
sql = "Your SQL Statement Here";

connection = new SqlConnection(connetionString);

command = new SqlCommand(sql, connection);
adapter.SelectCommand = command;

for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
MessageBox.Show(ds.Tables[0].Rows.ItemArray[0] + " -- " + ds.Tables[0].Rows.ItemArray[1]);

catch (Exception ex)
MessageBox.Show("Can not open connection ! ");

Learn crystal reports from the following .. c# crystal reports .. hope it wil lhelp you.

Top Bottom