TheProfezzor Posted November 20, 2012 Posted November 20, 2012 Hello, 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: A small application that pings a list of servers. The list is stored in a Access mdb file. When the application pings the PC's in a loop, it looks for any PC that's offline. 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. 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. There could be a button on the form, from where I can pull the logs to a grid of some sort. 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. 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 Quote
mandelbrot Posted December 28, 2012 Posted December 28, 2012 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... 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... 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... conn.Open() '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 Loop 'Close and tidy-up... reader.Close() conn.Close() reader = Nothing conn.Dispose() conn = Nothing End Sub This is a very basic form for what you are looking for. Hope this helps. Kind regards, Paul. Quote
robertsams23 Posted September 10, 2013 Posted September 10, 2013 A simple ado.net connection si follwoing... if you want to know more http://csharp.net-informations.com/data-providers/csharp-dataproviders-tutorial.htm 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); try { connection.Open(); command = new SqlCommand(sql, connection); adapter.SelectCommand = command; adapter.Fill(ds); adapter.Dispose(); command.Dispose(); connection.Close(); 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 .. http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-tutorial.htm c# crystal reports .. hope it wil lhelp you. robert. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.