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.
hear is a sample of the text file i am using:
VB.NET:
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.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
qry = "Insert into profile (identifier,bin,version_number,transaction_Code,farm_num,misc_ID," _
& "zip_shrt,DOB, Gender, date_Filled, subx_num, new_Refill, qty, total_supply, compound_code, " _
& "NDC_Num, driver_License, account_DEA, date_Written, num_Refills_Auth, origin_code, customer_loc, diagnostic_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(dbf.Count)
objwriter.WriteLine(ndx)
objwriter.WriteLine(qry)
Catch ex As Exception
MsgBox(ex)
End Try
ndx += 1
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
hear is a sample of the text file i am using:
VB.NET:
ABS,0,1,1,2506270,,386,19710713,2,20060115,1057435,3,30,30,0,63402019110,BD7774424,,20060115,5,0,0,,,KAMMAN,NICOLE,3621 LYLES DR.,MS,38655,,
ABS,0,1,1,2506270,,386,19661003,2,20060115,1063434,1,100,30,0,254501238,AH2675431,,20060115,2,0,0,,,HOLLINGER,PAM,515 CR 103 APT 1,MS,38601,,
ABS,0,1,1,2506270,4,386,19630709,1,20060115,1082885,1,30,30,0,24542131,BW2802836,,20060115,1,0,0,,,PHILLIPS,ANDY,9 HIGHLAND PLACE,MS,38655,,
ABS,0,1,1,2506270,3,386,19131105,2,20060115,1087839,0,150,7,0,406037516,BB8859273,,20060115,0,0,0,,,SMITH,FRANCES T,100 AZALEA DRIVE,MS,38655,,
ABS,0,1,1,2506270,,386,19190802,1,20060115,1087844,0,30,30,0,63402019110,BD7774424,,20060115,0,0,0,,,WILLISTON,HAMLIN,362 A HWY 7 S,MS,38655,,
ABS,0,1,1,2506270,,386,19220920,2,20060115,1087852,0,20,3,0,406177205,AL0246632,,20060115,0,0,0,,,IVY,AVIE,404 CO RD 202,MS,38601,,