Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Question about DataGridView and a text file [modified]

Question about DataGridView and a text file [modified]

Scheduled Pinned Locked Moved Visual Basic
helpquestiondata-structuresdebuggingtutorial
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Psycho Coder Extreme
    wrote on last edited by
    #1

    Here's what I'm trying to do, I have an ErrLog.txt file that logs any exceptions that happen in the application and I'm wanting to parse this file and load it into a DataGridView. The file (for now, I can change it if needed) is in this format:

    Title: Error title
    Message: ex.Message value
    StackTrace: Exception stack trace
    Date/Time: Date & Time it happened

    I'm fairly certain I'll need to make it a comma delimited file and have Title,Message,StackTrace,Date/Time as the first line (to handle the DataGridView Headers) but I'm really having a hard time wrapping my head around how to get the text from the file into the DataGridView. Anyone help with this or at least have somewhere I can start (I've Googled and haven't found much but theres always a chance I'm not using the right keywords but who knows)

    Last modified: 3hrs 40mins after originally posted --

    "Okay, I give up: which is NOT a real programming language????" Michael Bergman

    J 1 Reply Last reply
    0
    • P Psycho Coder Extreme

      Here's what I'm trying to do, I have an ErrLog.txt file that logs any exceptions that happen in the application and I'm wanting to parse this file and load it into a DataGridView. The file (for now, I can change it if needed) is in this format:

      Title: Error title
      Message: ex.Message value
      StackTrace: Exception stack trace
      Date/Time: Date & Time it happened

      I'm fairly certain I'll need to make it a comma delimited file and have Title,Message,StackTrace,Date/Time as the first line (to handle the DataGridView Headers) but I'm really having a hard time wrapping my head around how to get the text from the file into the DataGridView. Anyone help with this or at least have somewhere I can start (I've Googled and haven't found much but theres always a chance I'm not using the right keywords but who knows)

      Last modified: 3hrs 40mins after originally posted --

      "Okay, I give up: which is NOT a real programming language????" Michael Bergman

      J Offline
      J Offline
      Johan Hakkesteegt
      wrote on last edited by
      #2

      Hi, You could try and adapt the way your ErrLog.txt file gets written, or use a streamreader to read through the file, but you could also consider one of the following two alternatives: 1. Forget about the DataGridView; ideally nobody will ever have to look at the information in the file, or better, nothing will ever get written to it. In other words, you will need very little access to this information, so why put an inordinate amount of time in developing this idea, when you can put the data in a ListBox, with minimal effort, or even just open the text file by hand. Ofcourse this depends on the average amount of errors thrown. 2. Forget about ErrLog.txt;

      Psycho-*Coder*-Extreme wrote:

      I'm fairly certain I'll need to make it a comma delimited file

      Whether this or some other solution, in the end you will have to change the way your app writes the error data to the file. So consider the easiest way to fill a datagrid, which I would say is a dataset. The easiest way to fill a dataset from a file, is with the use of xml. I.e. your app runs > an error is thrown > an entry is made in DS_ErrorLog1 > DS_ErrorLog1 is the data source for the datagrid > push the button, et voila, the datagrid is shown. (and if you want:) > when the app is closed you call DS_ErrorLog1.WriteXml("ErrorLog.xml"), and when the app is launched you call DS_ErrorLog1.ReadXml("ErrorLog.xml") Johan

      My advice is free, and you may get what you paid for.

      P 1 Reply Last reply
      0
      • J Johan Hakkesteegt

        Hi, You could try and adapt the way your ErrLog.txt file gets written, or use a streamreader to read through the file, but you could also consider one of the following two alternatives: 1. Forget about the DataGridView; ideally nobody will ever have to look at the information in the file, or better, nothing will ever get written to it. In other words, you will need very little access to this information, so why put an inordinate amount of time in developing this idea, when you can put the data in a ListBox, with minimal effort, or even just open the text file by hand. Ofcourse this depends on the average amount of errors thrown. 2. Forget about ErrLog.txt;

        Psycho-*Coder*-Extreme wrote:

        I'm fairly certain I'll need to make it a comma delimited file

        Whether this or some other solution, in the end you will have to change the way your app writes the error data to the file. So consider the easiest way to fill a datagrid, which I would say is a dataset. The easiest way to fill a dataset from a file, is with the use of xml. I.e. your app runs > an error is thrown > an entry is made in DS_ErrorLog1 > DS_ErrorLog1 is the data source for the datagrid > push the button, et voila, the datagrid is shown. (and if you want:) > when the app is closed you call DS_ErrorLog1.WriteXml("ErrorLog.xml"), and when the app is launched you call DS_ErrorLog1.ReadXml("ErrorLog.xml") Johan

        My advice is free, and you may get what you paid for.

        P Offline
        P Offline
        Psycho Coder Extreme
        wrote on last edited by
        #3

        Johan, Thanks for the ideas. When first created the error log I didn't have the idea of a reader for it so I didn't bother with a comma delimited file, now I know that part I'm going to have to change. Some of the errors are unavoidable, we are dealing with an off-site 3rd party that my application is communicating with, and given a process, one of 55+ errors can be returned, some of which can cause the application to "not act so nicely". I feel I have done an adequate job of exception handling, but I don't feel that for the other developer working on this with me (thus the reason behind the error log to begin with. I am creating and implementing this so when an error does occur (60% of which is from teh 3rd party host), Id like to be able to go to the users desk, open the log viewer and find the error, even sort by date. I still like the writing it to the text file, but I can always convert it to a DataSet then populate the grid from there, I was just hoping for possibly a cleaner solution.

        J 1 Reply Last reply
        0
        • P Psycho Coder Extreme

          Johan, Thanks for the ideas. When first created the error log I didn't have the idea of a reader for it so I didn't bother with a comma delimited file, now I know that part I'm going to have to change. Some of the errors are unavoidable, we are dealing with an off-site 3rd party that my application is communicating with, and given a process, one of 55+ errors can be returned, some of which can cause the application to "not act so nicely". I feel I have done an adequate job of exception handling, but I don't feel that for the other developer working on this with me (thus the reason behind the error log to begin with. I am creating and implementing this so when an error does occur (60% of which is from teh 3rd party host), Id like to be able to go to the users desk, open the log viewer and find the error, even sort by date. I still like the writing it to the text file, but I can always convert it to a DataSet then populate the grid from there, I was just hoping for possibly a cleaner solution.

          J Offline
          J Offline
          Johan Hakkesteegt
          wrote on last edited by
          #4

          Hi, I see your problem. Once again I recommend xml over delimited text, simply because the basic principle is pretty much the same, but getting data from an xml file into a datagrid is more straightforward. Otherwise feel free to use this code in your error handling: ;) Public Function SendEmail(ByVal oFrom As String, ByVal oTo As String, ByVal oSubject As String, ByVal oText As String, Optional ByVal oCC As String = "", Optional ByVal oBCC As String = "", Optional ByVal oPri As Integer = 0) Try Dim mailmsg As New System.Web.Mail.MailMessage With mailmsg .From = oFrom **.To = "your.colleague.coder@yourcompanyname.com"** .Cc = oCC .Bcc = oBCC .Subject = oSubject **.Body = "You suck!!!"** .Priority = oPri End With System.Web.Mail.SmtpMail.SmtpServer = "smtp_server_name" System.Web.Mail.SmtpMail.Send(mailmsg) Catch Ex As Exception MsgBox(Ex.Message) End Try End Function I Hope you manage to solve the problem, good luck, Johan

          My advice is free, and you may get what you paid for.

          P 1 Reply Last reply
          0
          • J Johan Hakkesteegt

            Hi, I see your problem. Once again I recommend xml over delimited text, simply because the basic principle is pretty much the same, but getting data from an xml file into a datagrid is more straightforward. Otherwise feel free to use this code in your error handling: ;) Public Function SendEmail(ByVal oFrom As String, ByVal oTo As String, ByVal oSubject As String, ByVal oText As String, Optional ByVal oCC As String = "", Optional ByVal oBCC As String = "", Optional ByVal oPri As Integer = 0) Try Dim mailmsg As New System.Web.Mail.MailMessage With mailmsg .From = oFrom **.To = "your.colleague.coder@yourcompanyname.com"** .Cc = oCC .Bcc = oBCC .Subject = oSubject **.Body = "You suck!!!"** .Priority = oPri End With System.Web.Mail.SmtpMail.SmtpServer = "smtp_server_name" System.Web.Mail.SmtpMail.Send(mailmsg) Catch Ex As Exception MsgBox(Ex.Message) End Try End Function I Hope you manage to solve the problem, good luck, Johan

            My advice is free, and you may get what you paid for.

            P Offline
            P Offline
            Psycho Coder Extreme
            wrote on last edited by
            #5

            I would love nothing more than to do this, but I got a feeling it would catch the eyre of my superiors :laugh:

            "Okay, I give up: which is NOT a real programming language????" Michael Bergman

            "Well yes, it is an Integer, but it's a metrosexual Integer. For all we know, under all that hair gel it could be a Boolean." Tom Welch

            "Let's face it, the average computer user has the brain of a Spider Monkey." Bill Gates

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups