Information générale
Catégorie:
Code, syntaxe and commandes
Titre:
Inserting a record into a FoxPro's free table using VB.Net
Versions des environnements
Dear developers.....
I develop applications using VFP6.0 and VB.NET.
Currently, I'm developing a VB.NET application and having a difficulty
inserting a record into a FoxPro's free table using VB.Net.
Everything ran smoothly until the program hit the following line in Private Sub update_lwinfile()
objCM.ExecuteNonQuery() '<-- VB.NET doesn't like this.
We use VFP 6.0 so I can only use the ODBC to get to the foxpro free
table. Could you help me on this? Thank you.
Please see the following codes. (Note: I have no problem extracting
data from FoxPro table.)
*****************************************************************
Private Function getMaxKey() As Integer
'This function works, so this is OK
Dim strSQL As String
Dim objCM As Odbc.OdbcCommand
'create the dataset
Dim objDR As Odbc.OdbcDataReader
Dim objDS As DataSet = New DataSet
Dim intMaxKey As Integer
Dim strMaxKey As String
FoxConn.Open()
'sql string to perform
strSQL = "SELECT MAX(NKEY) as MaxNkey FROM lwinfile"
objCM = New Odbc.OdbcCommand(strSQL, FoxConn)
objDR = objCM.ExecuteReader
While objDR.Read
strMaxKey = objDR("MaxNkey")
End While
intMaxKey = Integer.Parse(strMaxKey)
FoxConn.Close()
Return intMaxKey
End Function
*****************************************************************
Private Sub update_lwinfile()
'Everything runs smooth until the end of the program
'ie When the line "objCM.ExecuteNonQuery()" hits
Dim strSQL As String
Dim objCM As Odbc.OdbcCommand
'create the dataset
Dim objDR As Odbc.OdbcDataReader
Dim objDS As DataSet = New DataSet
Dim strProduct As String
Dim strCtype As String
Dim intMaxKey As Integer
intMaxKey = getMaxKey() + 1
FoxConn.Open()
If rbNico.Checked Then
strProduct = "NICO-RATE"
strCtype = "NICORATE"
Else
strProduct = "Garage"
strCtype = "ZGARAGE"
End If
strProduct = strProduct + " for " + cboVersion.Text + " " +
cboCompany.Text
strSQL = "INSERT INTO lwinfile (Ctype, Ctitle, Cdirectory, Cprogram, Cauthority, Nkey) "
strSQL = strSQL + "VALUES ('" + strCtype + "', '" + strProduct
strSQL = strSQL + "','N:\NICO\NICORATE\MN\VERS63', "
strSQL = strSQL + "'MN-ratew.exe', 1, " + intMaxKey.ToString + ")"
objCM = New Odbc.OdbcCommand(strSQL, FoxConn)
objCM.ExecuteNonQuery() '<-- VB.NET doesn't like this.
FoxConn.Close()
End Sub
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement