-
Dec 4th, 2017, 11:57 PM
#1
Thread Starter
Junior Member
[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
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..
-
Dec 5th, 2017, 06:36 AM
#2
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.
-
Dec 5th, 2017, 06:20 PM
#3
Thread Starter
Junior Member
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.
-
Dec 9th, 2017, 01:58 AM
#4
Thread Starter
Junior Member
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.
-
Dec 9th, 2017, 06:44 AM
#5
Re: From dat File to DataGridView to Ms Access Table
Originally Posted by lance1578
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.
-
Dec 11th, 2017, 05:46 PM
#6
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|