" SELECT into statement"内循环不起作用

时间:2013-10-02 07:30:43

标签: sql vb.net

我有 select into语句,但是当我把它放在循环中时,它会失败。 有谁知道为什么会发生这种情况?

谢谢!

以下是代码:

For o = 0 To x

            tables = ListBox1.Items.Item(o).ToString
            sqlstr = "SELECT * into dbo." & tables & " FROM OPENROWSET('MSDASQL', 'Driver=Microsoft Visual FoxPro Driver; SourceDB=C:\exports\DBF; SourceType = DBF ', 'SELECT * FROM " & tables & "')"
            mycmd = New SqlCommand
            sqlcon = New SqlConnection(con)
            mycmd.CommandText = sqlstr
            sqlcon.Open()
            mycmd.Connection = sqlcon
            mycmd.ExecuteNonQuery()
            sqlcon.Close()
Next

当我尝试执行此操作时,它会给我以下错误

    Cannot execute the query "SELECT * FROM AFED" against OLE DB provider "MSDASQL" 
for linked server "(null)". OLE DB provider "MSDASQL" 
for linked server "(null)" returned message 
"[Microsoft][ODBC Visual FoxPro Driver]File 'afed.dbf' does not exist.".

1 个答案:

答案 0 :(得分:0)

请检查您的foxpro数据库..我认为foxpro数据库中不存在afed表。这就是为什么在放置静态值而不是o时没有收到错误。