dcsimg
Results 1 to 6 of 6

Thread: [RESOLVED] From dat File to DataGridView to Ms Access Table

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    22

    Resolved [RESOLVED] From dat File to DataGridView to Ms Access Table

    I successfully manage to load the .dat file from the DataGridView using the below code.

    Code:
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles btnToTable.Click
            Dim fname As String = TextBox1.Text
            Dim colsexpected As Integer = 6
            Dim FileReader As New StreamReader(fname, Encoding.Default)
            Dim sLine As String = ""
    
    
            Do
                    sLine = FileReader.ReadLine
                    If sLine Is Nothing Then Exit Do
                    Dim words() As String = sLine.Split(vbTab)
                    dgdataReader.Rows.Add("")
                    For xcolumn As Integer = 0 To 5
                        dgdataReader.Rows(dgdataReader.Rows.Count - 1).Cells(xcolumn).Value = words(xcolumn)
                    Next
                Loop
    
            dgdataReader.Sort(dgdataReader.Columns(0), System.ComponentModel.ListSortDirection.Ascending)
            FileReader.Close()
            btnToTable.Enabled = False
            Button2.Enabled = False
            Button1.Enabled = False
            TextBox1.Clear()
    
    
            'Filter_MachineID()
        End Sub
    Name:  Capture_299.jpg
Views: 253
Size:  32.2 KB

    Now my problem is I dont know how to save the dgdataReader data to MS Access Table and show data in dgTempTable. I try searching the site but i cant find exactly what i want.

    dgdataReader data = Extracted data from .dat File
    dgTempTable = is not bounded to the table

    I want to save all the data in dgdataReader to tblTempdata(fldmachineId,fldLogDate,fldV1,fldV2,fldV3,fldv4) then show the data to dgTempTable.

    I have created this program in VB6 but since new windows are not supporting it. I decided to recreate my old program to .net, I'm not a .net programmer and I know a little of .net. Hope you lend a little help in my post. Thank you very much in advanced..

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,053

    Re: From dat File to DataGridView to Ms Access Table

    Don't load the data into the DataGridView directly. Load it into a DataTable and bind that to the grid to display the data. You can then use an OleDbDataAdapter to save the data from the DataTable to your database. Follow the CodeBank link in my signature below and check out my thread on Retrieving & Saving Data for an example. Note that the example most relevant to you is in post #3.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    22

    Re: From dat File to DataGridView to Ms Access Table

    Thank you very much.. I give it a try.. I keep you posted later thanks for your time.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    22

    Re: From dat File to DataGridView to Ms Access Table

    Hi @jmcilhinney

    I already check your code banks but it seems that is not the answer i need. I want to load the dat file to ms access table and show it using DataGridView. If you say that i dont need to load it to DataGridView then to datatable then that would be faster. I will try to do your suggestion and get back soon. Thanks for you time.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,053

    Re: From dat File to DataGridView to Ms Access Table

    Quote Originally Posted by lance1578 View Post
    I already check your code banks but it seems that is not the answer i need.
    I'm fairly certain that it's pretty close to exactly what you need.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    22

    Re: From dat File to DataGridView to Ms Access Table

    @jmcilhinney

    Thank you very much.. I found the answer based on your codebank examples.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width