5 Replies - 429 Views - Last Post: 25 March 2011 - 08:19 AM Rate Topic: -----

#1 fachagooch  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 10-March 10

Trying to connect a field from a text file to Access DB

Posted 23 March 2011 - 10:34 PM

I am working on a project for work where i am stuck. We have a daily checklist that i have converted into a Tabular text file. In the text file I have 3 pieces of information, DB field reference, Time it should be done by, and task to be completed. I have this part being pulled into the screen with the Code below. This isn't the problem, My problem is how do i Merge the Database to the TextBox.

The Access DB has 50 Columns of for data Labeled 1 through 50 + one date Field

I have looked but have been unsuccessful in finding anything that can help.


Imports System.IO

Public Class FirstShiftCheckListForm

Dim strlines() As String
    Dim strline() As String
    Dim strarray(,) As String
    Dim num_rows As Integer
    Dim num_cols As Integer
    Dim xAxis As Integer = 50
    Private Sub LoadDB()

    End Sub

    Private Sub FirstShiftCheckListForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



        Dim strfilename As String   ' to be used as the location of the File Name
        Dim x As Integer
        Dim y As Integer

        ' Load the file.
        strfilename = "C:\ef53734\OperatorChecklist\Checklists\FirstShift.txt"

        'Check if file exist
        Try
            If File.Exists(strfilename) Then
                Dim sr As StreamReader = File.OpenText(strfilename)
                'Load content of file to strLines array
                strlines = sr.ReadToEnd().Split(Environment.NewLine)
                ' Redimension the array.
                num_rows = UBound(strlines)
                strline = strlines(0).Split(Chr(9))
                num_cols = UBound(strline)
                ReDim strarray(num_rows, num_cols)
                ' Loads the data into the array, and builds the Link lables on the page.
                For x = 1 To num_rows
                    strline = strlines(x).Split(Chr(9))
                    For y = 0 To num_cols
                        strarray(x, y) = strline(y)

                    Next
                    AddTextLabel(y, strarray(x, 0), strarray(x, 1), strarray(x, 2))
                Next
                sr.Close()
            End If
            'Place move the save button here
            LoadDB()

        Catch ex As Exception
        End Try
    End Sub
    Sub AddTextBox(ByVal DBLabel As String)
        Dim myTextBox As New TextBox
        myTextBox.Size = New System.Drawing.Size(85, 22)
        myTextBox.Location = New Point(15, xAxis)
        myTextBox.Name = DBLabel
        Me.Controls.Add(myTextBox)
    End Sub

    Sub AddTextLabel(ByVal Y As Integer, ByVal DBLabel As String, ByVal Text1 As Integer, ByVal Text2 As String)
        Dim myLabel As New Label
        Dim Time As String
        If Text1 = 0 Then
            Time = CStr("")
            myLabel.Font = New System.Drawing.Font("Microsoft Sans Serif", 7.8!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Else
            AddTextBox(DBLabel)
            Time = CStr(Format(Text1, "00:00"))
        End If
        myLabel.Text = Time + ("    ") + Text2
        myLabel.AutoSize = True
        myLabel.Location = New Point(100, xAxis)
        xAxis = xAxis + 28
        Me.Controls.Add(myLabel)
    End Sub
End Class




Tab Deliminated
[SampleData]
0 Time Task
1 700 "Complete any pending Daily Tape Management sheets print all labels, chg f=lble (etc) to f=3lbl prt=local or opshq008"
2 700 "BOTH printer settings match paper setting on printer (both should have punch, unless you are printing special forms)"
3 700 "Walkabout ALL ROOMS looking for trouble/problems/air conditioners, etc.
[/SampleData]

Is This A Good Question/Topic? 0
  • +

Replies To: Trying to connect a field from a text file to Access DB

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9080
  • View blog
  • Posts: 34,127
  • Joined: 12-June 08

Re: Trying to connect a field from a text file to Access DB

Posted 24 March 2011 - 07:09 AM

Can you elaborate on "how do i Merge the Database to the TextBox."? I am not getting what you are asking to do.

From what I read you have this app. It loads a checklist from a text file. It creates some labels and textboxes based off your data from the text file. Where does this database come in?
Was This Post Helpful? 0
  • +
  • -

#3 fachagooch  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 10-March 10

Re: Trying to connect a field from a text file to Access DB

Posted 24 March 2011 - 07:42 PM

The Database is the problem that i am having, I want to associate the Data that goes into the text box with the DB.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9080
  • View blog
  • Posts: 34,127
  • Joined: 12-June 08

Re: Trying to connect a field from a text file to Access DB

Posted 24 March 2011 - 09:36 PM

You want to read data to a grid and write it back to a database? Is that what you are looking for?
Was This Post Helpful? 0
  • +
  • -

#5 fachagooch  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 10-March 10

Re: Trying to connect a field from a text file to Access DB

Posted 24 March 2011 - 10:21 PM

Yes that is what i am looking for.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9080
  • View blog
  • Posts: 34,127
  • Joined: 12-June 08

Re: Trying to connect a field from a text file to Access DB

Posted 25 March 2011 - 08:19 AM

Cool - well we have some pretty awesome tutorials on getting data to and from a database. Here are two fine examples:

http://www.dreaminco...asics-in-vbnet/
http://www.dreaminco...imple-database/

Go nuts!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1