update dbase file with function

J

JFB

Hi,
I have a connection to a dbase IV file using oledb. I wan to do an update to
a field using a vb function passing two parameters. These 2 parameters are
fields from the same table.
What is the sintax to do this?
Thanks

JFB

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
filePath & ";Extended Properties=dBase IV"

Dim dBaseConnection As New
System.Data.OleDb.OleDbConnection(ConnectionString)

Try

dBaseConnection.Open()

Dim dBaseCommand As New System.Data.OleDb.OleDbCommand("update " & dbfFile &
" set Column4 = FSB(Column1, Column2)", dBaseConnection)

dBaseCommand.ExecuteNonQuery()

Catch ex As Exception

MsgBox(ex.ToString)

Finally

dBaseConnection.Close()

End Try

Function FSB(ByVal inTrack As String, ByVal inRoute As String) As String

bla...bla....

End Function
 
J

JFB

Got it... FYI

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
filePath & ";Extended Properties=dBase IV"

Dim dBaseConnection As New
System.Data.OleDb.OleDbConnection(ConnectionString)

Try

dBaseConnection.Open()

Dim dBaseCommand As New System.Data.OleDb.OleDbCommand("select * from " &
dbfFile, dBaseConnection)

Dim dBaseDataReader As System.Data.OleDb.OleDbDataReader =
dBaseCommand.ExecuteReader(CommandBehavior.SequentialAccess)

While dBaseDataReader.Read

Dim parameter1 As String = dBaseDataReader("Colum2").ToString

Dim parameter2 As String = dBaseDataReader("Colum3").ToString

Dim updateCommand As New System.Data.OleDb.OleDbCommand("update " & dbfFile
& " set Column4 = '" & FSB(parameter1, parameter2) & "' where Column2 = '" &
parameter1 & "' and Column3 = '" & parameter2 & "'", dBaseConnection)

updateCommand.ExecuteNonQuery()

End While

Catch ex As Exception

MsgBox(ex.ToString)

Finally

dBaseConnection.Close()

End Try
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top