从SQL Server错误中检索数据

时间:2013-07-09 19:01:02

标签: .net sql sql-server vb.net ms-access-2010

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

    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()

1 个答案:

答案 0 :(得分: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 是模式名称,应与表名称分隔句点