Warm tip: This article is reproduced from stackoverflow.com, please click
indexing vb.net command visual-foxpro foxpro

FoxPro Command to VB.NET

发布于 2020-04-04 10:11:31

I 'm running a FoxPro Command in Visual Studio 2017. I want To execute the second command text pre-requisite To the first, And so on. Any help?

Dim a = "Provider=VFPOLEDB.1;Data Source=C:\temp;Extended Properties=dBase IV"

Using cn As New OleDbConnection(a)
    cn.Open()

    Dim cmd As New OleDbCommand
    cmd.Connection = cn
    cmd.CommandText = "use C:\temp\products"
    cmd.ExecuteNonQuery()

    cmd.CommandText = "INDEX ON productid TAG productid"
    cmd.ExecuteNonQueryAsync()

    cmd.CommandText = "INDEX ON prodname TAG prodname"
    cmd.ExecuteNonQueryAsync()

    cn.Close()
End Using
Questioner
404notfound
Viewed
82
Alan B 2020-02-27 22:00

You need to use the Visual FoxPro ExecScript() command and don't execute the the commands asynchronously.

Dim a = "Provider=VFPOLEDB.1;Data Source=C:\temp;Extended Properties=dBase IV"

Using cn As New OleDbConnection(a)
    cn.Open()

    Dim cmd As New OleDbCommand
    cmd.Connection = cn
    cmd.CommandText = "execscript(['use C:\temp\products excl'])"
    cmd.ExecuteNonQuery()

    cmd.CommandText = "execscript(['INDEX ON productid TAG productid'])"
    cmd.ExecuteNonQuery()

    cmd.CommandText = "execscript(['INDEX ON prodname TAG prodname'])"
    cmd.ExecuteNonQuery()

    cn.Close()
End Using