-1

我已连接到 Access 2010 数据库中的 SQL 服务器。但我需要从服务器检索一个字符串。当我运行程序时,我收到错误消息Invalid object name 'dbo_b_Pulp_PI_Forte'。当程序命中时run.ExecuteReader()。我找不到问题。这是我的代码:

    Dim myCmd As String
    Dim strConn1 As New OleDb.OleDbConnection
    Dim CmdCommand As New OleDb.OleDbCommand
    'Connection string for SQL Server.
    strConn1.ConnectionString = "Provider=SQLOLEDB;Server=THIPSQLW01;Database=wss_Test;Uid=baletrack;Pwd=BaleTrack;"

    'SQL statement for SQL Server.
    myCmd = "SELECT TOP 1 * FROM dbo_b_Pulp_PI_Forte WHERE Mill = '850' and Pulp_Line_id = '" & stBaleLine & "' ORDER BY keyprinter_datetime DESC, bale_id DESC"

    'Open server.
    strConn1.Open()

    Dim run = New OleDb.OleDbCommand
    'Using the SQL statement in the SQL server.
    run = New OleDbCommand(myCmd, strConn1)
    run.ExecuteReader()
4

1 回答 1

3

改变这个:

   'SQL statement for SQL Server.
        myCmd = "SELECT TOP 1 * FROM dbo_b_Pulp_PI_Forte 
        WHERE Mill = '850' and Pulp_Line_id = '" & stBaleLine & "' 
        ORDER BY keyprinter_datetime DESC, bale_id DESC"

   'SQL statement for SQL Server.
        myCmd = "SELECT TOP 1 * FROM dbo.b_Pulp_PI_Forte 
        WHERE Mill = '850' and Pulp_Line_id = '" & stBaleLine & "' 
        ORDER BY keyprinter_datetime DESC, bale_id DESC"

dbo是模式名称,应与表名称用句点分隔

于 2013-07-09T19:19:36.233 回答