Trying to write out from VB.net to a table in Foxpro and getting error - Argument 'Prompt' cannot be

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im trying to write out records to a table in Visual FoxPro from VB.net.
Currently, the data is shown in a DataGridView. Im taking it from there, one record at a time, and assigning each cells contents to a variable. All variables are declared as strings.
Once each field from the current record of the DGV is assigned to a variable, Im trying to pass it over to FoxPro. Im getting the following error when I try to execute Cmd.ExecuteNonQuery():
Argument Prompt cannot be converted to type String
I thought this would be because I was trying to pass a string into a cell in the table that was defined as something else, like integer, but this isnt the case. All cells in the table are defined as type character.
Could someone please take a look at my code and tell me what Im doing wrong?
<pre class="prettyprint lang-vb Dim Conn As New System.Data.OleDb.OleDbConnection
Dim Cmd As New System.Data.OleDb.OleDbCommand
Dim inputTabPath As String
inputTabPath = "c:"
Conn.ConnectionString = "Provider=VFPOLEDB.1;Data Source=" & _
inputTabPath & ";Exclusive=No;Mode=ReadWrite|Share Deny None;Collating Sequence=MACHINE"
Dim I As Integer = 0
Dim j As Integer = 0
Dim cellvalue As String
Dim rowLine As String = ""
Dim _cati_id As String = ""
Dim _address1 As String = ""
Dim _address2 As String = ""
Dim _city As String = ""
Dim _state As String = ""
Dim _zip As String = ""
Dim _zip4 As String = ""
Dim _filler1 As String = ""
Dim _geozip As String = ""
Dim _market As String = ""
Dim _name As String = ""
Dim _areacode As String = ""
Dim _dash1 As String = ""
Dim _phonest As String = ""
Dim _dash2 As String = ""
Dim _phoneend As String = ""
Dim _age As String = ""
Dim _respgender As String = ""
Dim _rind As String = 0
Dim SetField As Integer = 0
Try
For j = 0 To (Joni_DataGridView.Rows.Count - 1)
For I = 0 To (Joni_DataGridView.Columns.Count - 1)
If Not TypeOf Joni_DataGridView.CurrentRow.Cells.Item(I).Value Is DBNull Then
cellvalue = Joni_DataGridView.Item(I, j).Value
Else
cellvalue = ""
End If
rowLine = cellvalue
Select Case SetField
Case 0
_cati_id = rowLine
Case 1
_address1 = rowLine
Case 2
_address2 = rowLine
Case 3
_city = rowLine
Case 4
_state = rowLine
Case 5
_zip = rowLine
Case 6
_zip4 = rowLine
Case 7
_filler1 = rowLine
Case 8
_geozip = rowLine
Case 9
_market = rowLine
Case 10
_name = rowLine
Case 11
_areacode = rowLine
Case 12
_dash1 = rowLine
Case 13
_phonest = rowLine
Case 14
_dash2 = rowLine
Case 15
_phoneend = rowLine
Case 16
_age = rowLine
Case 17
_respgender = rowLine
Case 18
_rind = rowLine
End Select
SetField += 1

Next
rowLine = ""
SetField = 0
Conn.Open()
Cmd.CommandType = System.Data.CommandType.Text
Cmd.CommandText = "INSERT INTO c:mytable (cati_id, address1, address2, city," & _
" state, zip, zip4, filler1, geozip, market, name, areacode, dash1," & _
" phonest, dash2, phoneend, age, respgender, rind)" & _
" VALUES (" + _cati_id + " , " + _address1 + "," + _city + " , " + _state + " ," + _zip + " ," + _zip4 + " ," + _filler1 + " ," + _geozip + " ," + _market + " ," + _name + " ," + _areacode + " ," + _dash1 + " ," + _phonest + " ," + _dash2 + " ," + _phoneend + " ," + _age + " ," + _respgender + " ," + _rind + " )"

Cmd.Connection = Conn
Cmd.ExecuteNonQuery()
Next

Catch ex As Exception
MsgBox(ex, MsgBoxStyle.Critical, "Error")
Finally
Conn.Close()
Conn = Nothing
End Try[/code]
<br/><hr class="sig -Joni :)

View the full article
 
Back
Top