Quantcast
Channel: loopinh and string problem
Viewing all articles
Browse latest Browse all 7

loopinh and string problem

$
0
0
I have a problem loading my data to my database. I am using mysql. I noticed the problem when i executed my code and it kept giving me a "Argument 'Prompt' cannot be converted to type 'String'" error. But when i checked the db it had some the information in there it would not have the last 3 or 4 data entries in the db. I went back to check the string that was providing the command and I saw that the program was running most of the commands correctly however close to the bottom of the script it was cutting the command off and so the db could process the rest of the information. Can anyone tell me why the data is getting cut off. here is my code it is for a winform app. the problem i found. I sent the qry variable's output to a text file and it will run all of the text strings i specify in a loop except the last 3 or 4 lines.

for example let's say my variable "qry" is equal to: ->"This is a test of the emergency broadcast system".  <-:

In my program if i looped this statement let's say 18 times it would print out the statement about 16 times and then cut the next line and not even show the 18th line like this
16: this is a test of the emergency broadcast system
17: this is a test of the
18:
this the reason the mysql is throwing the error because it is not getting a full command. I am trying to figure out why my program is cutting the lines off.


Imports System.Data
Imports MySql.Data.MySqlClient
Imports System
Imports System.IO


Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor.
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Submit_Btn As System.Windows.Forms.Button
    Friend WithEvents Browse_btn As System.Windows.Forms.Button
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents cur_date As System.Windows.Forms.Label
    Friend WithEvents cur_time As System.Windows.Forms.Label
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents FolderBrowserDialog1 As System.Windows.Forms.FolderBrowserDialog
    Friend WithEvents filebox As System.Windows.Forms.TextBox
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar
    Friend WithEvents StatusBarPanel1 As System.Windows.Forms.StatusBarPanel
    Friend WithEvents StatusBarPanel2 As System.Windows.Forms.StatusBarPanel
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim configurationAppSettings As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader
        Me.Label2 = New System.Windows.Forms.Label
        Me.Browse_btn = New System.Windows.Forms.Button
        Me.filebox = New System.Windows.Forms.TextBox
        Me.Submit_Btn = New System.Windows.Forms.Button
        Me.Label3 = New System.Windows.Forms.Label
        Me.cur_date = New System.Windows.Forms.Label
        Me.cur_time = New System.Windows.Forms.Label
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.FolderBrowserDialog1 = New System.Windows.Forms.FolderBrowserDialog
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.StatusBar1 = New System.Windows.Forms.StatusBar
        Me.StatusBarPanel1 = New System.Windows.Forms.StatusBarPanel
        Me.StatusBarPanel2 = New System.Windows.Forms.StatusBarPanel
        CType(Me.StatusBarPanel1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.StatusBarPanel2, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.Color.Transparent
        Me.Label2.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.Label2.ForeColor = System.Drawing.Color.Black
        Me.Label2.Location = New System.Drawing.Point(0, 8)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(168, 16)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "File to UPLoad:"
        '
        'Browse_btn
        '
        Me.Browse_btn.ForeColor = System.Drawing.Color.Black
        Me.Browse_btn.Location = New System.Drawing.Point(384, 48)
        Me.Browse_btn.Name = "Browse_btn"
        Me.Browse_btn.Size = New System.Drawing.Size(104, 24)
        Me.Browse_btn.TabIndex = 3
        Me.Browse_btn.Text = "Browse"
        '
        'filebox
        '
        Me.filebox.Location = New System.Drawing.Point(0, 48)
        Me.filebox.Name = "filebox"
        Me.filebox.Size = New System.Drawing.Size(376, 20)
        Me.filebox.TabIndex = 2
        Me.filebox.Text = ""
        '
        'Submit_Btn
        '
        Me.Submit_Btn.ForeColor = System.Drawing.Color.Black
        Me.Submit_Btn.Location = New System.Drawing.Point(0, 120)
        Me.Submit_Btn.Name = "Submit_Btn"
        Me.Submit_Btn.Size = New System.Drawing.Size(104, 24)
        Me.Submit_Btn.TabIndex = 3
        Me.Submit_Btn.Text = "Submit"
        '
        'Label3
        '
        Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.ForeColor = System.Drawing.Color.Black
        Me.Label3.Location = New System.Drawing.Point(0, 216)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(312, 23)
        Me.Label3.TabIndex = 4
        '
        'cur_date
        '
        Me.cur_date.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cur_date.ForeColor = System.Drawing.Color.Black
        Me.cur_date.Location = New System.Drawing.Point(480, 0)
        Me.cur_date.Name = "cur_date"
        Me.cur_date.Size = New System.Drawing.Size(136, 16)
        Me.cur_date.TabIndex = 5
        '
        'cur_time
        '
        Me.cur_time.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cur_time.ForeColor = System.Drawing.Color.Black
        Me.cur_time.Location = New System.Drawing.Point(480, 24)
        Me.cur_time.Name = "cur_time"
        Me.cur_time.Size = New System.Drawing.Size(136, 16)
        Me.cur_time.TabIndex = 5
        '
        'Timer1
        '
        Me.Timer1.Enabled = True
        '
        'FolderBrowserDialog1
        '
        Me.FolderBrowserDialog1.SelectedPath = "C:\Documents and Settings\rwoodard.MSBML_REGGIE\Desktop"
        '
        'StatusBar1
        '
        Me.StatusBar1.Location = New System.Drawing.Point(0, 254)
        Me.StatusBar1.Name = "StatusBar1"
        Me.StatusBar1.Panels.AddRange(New System.Windows.Forms.StatusBarPanel() {Me.StatusBarPanel1, Me.StatusBarPanel2})
        Me.StatusBar1.ShowPanels = True
        Me.StatusBar1.Size = New System.Drawing.Size(624, 16)
        Me.StatusBar1.TabIndex = 6
        Me.StatusBar1.Text = "StatusBar1"
        '
        'StatusBarPanel1
        '
        Me.StatusBarPanel1.Text = "StatusBarPanel1"
        Me.StatusBarPanel1.ToolTipText = CType(configurationAppSettings.GetValue("connection status", GetType(System.String)), String)
        Me.StatusBarPanel1.Width = 225
        '
        'StatusBarPanel2
        '
        Me.StatusBarPanel2.Text = "StatusBarPanel2"
        Me.StatusBarPanel2.Width = 200
        '
        'Form1
        '
        Me.AllowDrop = True
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.SystemColors.ActiveBorder
        Me.ClientSize = New System.Drawing.Size(624, 270)
        Me.Controls.Add(Me.StatusBar1)
        Me.Controls.Add(Me.cur_date)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Browse_btn)
        Me.Controls.Add(Me.filebox)
        Me.Controls.Add(Me.Submit_Btn)
        Me.Controls.Add(Me.cur_time)
        Me.ForeColor = System.Drawing.Color.White
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
        Me.Name = "Form1"
        Me.Text = "MSBML DataBaseImporter"
        CType(Me.StatusBarPanel1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.StatusBarPanel2, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Dim db_conn As MySqlConnection
    Dim mysql_cmd As MySqlCommand
    Dim qry, dbf_holder As String
    Dim file, file2 As String
    Dim ndx, ndx2, j, c As Integer
    Dim dbf, dbf2 As ArrayList
    Dim manip_dbf() As String
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

       


        'Open Connection to Database if connection fails process dies
        Try
            db_conn = New MySqlConnection("server=localhost; user id=tester; password=tester; database=pmp; pooling=false")
            db_conn.Open()
            If (db_conn.State() = 1) Then
                StatusBarPanel1.Text = "Connected"
            End If

        Catch ex As Exception
            StatusBarPanel1.Text = "Connection Failed"
            MsgBox(ex)
        End Try






    End Sub


    Private Sub Browse_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse_btn.Click
        'If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
        'filebox.Text = FolderBrowserDialog1.SelectedPath
        ' End If
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            filebox.Text = OpenFileDialog1.FileName
        ElseIf (OpenFileDialog1.ShowDialog() = DialogResult.Cancel) Then
            Return
        End If

    End Sub



    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        cur_date.Text = Format(Now, "dd-MMM-yyyy")
        cur_time.Text = Format(Now, "HH:mm:ss")
    End Sub


    Private Sub Submit_Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit_Btn.Click
        Dim objreader As New StreamReader(filebox.Text)  ' read from text file
        Dim objwriter As New StreamWriter("c:\datafiles\scripts.txt")
        ndx = 1
        ndx2 = 1
        dbf = New ArrayList 'internal holder for data from textfile

        While objreader.Peek <> -1
            dbf.Add(objreader.ReadLine())
        End While

        While ndx2 < dbf.Count  'Data Formatter
            dbf_holder = dbf(ndx2)

            dbf_holder = dbf_holder.Replace(",,", ",' ',") 'formatting data for entrance in to database
            dbf_holder = dbf_holder.Replace(",,", ",' ',")
            dbf(ndx2) = dbf_holder


            manip_dbf = dbf(ndx2).split(",") 'divides text string in order to manipulate individual datafields

            j = 0
            While j <= manip_dbf.GetUpperBound(0)
                c = String.Compare("' '", manip_dbf(j))
                If c = 0 Then
                    j += 1
                ElseIf IsNumeric(manip_dbf(j)) = True Then
                    j += 1
                Else
                    manip_dbf(j) = "'" & manip_dbf(j) & "'"
                    j += 1
                End If

            End While

            dbf(ndx2) = String.Join(",", manip_dbf)


            ndx2 += 1
        End While
        'End of Data Formatting Section


        While (ndx < dbf.Count + 1)
            qry = "Insert into profile (identifier,bin,version_number,transaction_Code,pharm_num,patient_ID," _
            & "zip_shrt,pat_DOB, pat_Gender, date_Filled, Rx_num, new_Refill, met_qty, days_supply, compound_code, " _
            & "NDC_Num, doctor_License, doctor_DEA, date_Written, num_Refills_Auth, Rx_origin_code, customer_loc, diagnosis_code," _
            & "alternate_Prescriber, pat_Lname, pat_Fname, pat_Address, pat_State, pat_Zip, triplicate_Serial, payment_meth, date_entered" _
            & ")" _
            & " Values (" & dbf(ndx) & ", Now()" & ");"

            'mysql_cmd = New MySqlCommand(qry, db_conn)

            Try
                'Dim inserter As Integer = mysql_cmd.ExecuteNonQuery()

                objwriter.WriteLine(ndx)

                objwriter.WriteLine(qry)
                ndx += 1


            Catch ex As Exception
                MsgBox(ex)

            End Try

        End While
       
        'db_conn.Close()
        'db_conn.Dispose()
        'If (db_conn.State < 1) Then
        'StatusBarPanel1.Text = "Database Connection Closed"
        'End If

    End Sub

   
   
End Class


Viewing all articles
Browse latest Browse all 7

Latest Images

Trending Articles





Latest Images