0

VS2012wpfアプリケーションvb.netMSAccess 2010を使用しています。を介してクエリを実行しようとするoledbconnectionとエラーが返されますが、MS Access 2010を介して同じクエリを実行すると、問題なくテーブルが返されます。なにが問題ですか?

クエリ:

SELECT Agents.[PF], Agents.[User_ID], Agents.[First_Name], Agents.[Second_Name], Agents.[Third_Name], Agents.[Family_Name], Agents.[Gender], Agents.[Contract_Type], Agents.Area, Teams.Team_Name, Agents.Hiring_Date, Resignation_Pool.Resignation_Date, Resignation_Pool.Effective_Date, Replace(IIf(Skills.Skill_Directory Is Null,'','Directory, ')+IIf(Skills.Skill_TRC Is Null,'','TRC, ')+IIf(Skills.Skill_Prepaid Is Null,'','Prepaid, ')+IIf(Skills.Skill_Postpaid Is Null,'','Postpaid, ')+IIf(Skills.Skill_KeyAccount Is Null,'','KeyAccount, ')+IIf(Skills.Skill_Blackberry Is Null,'','Blackberry, ')+IIf(Skills.Skill_Broadband Is Null,'','Broadband, ')+IIf(Skills.Skill_Concierge Is Null,'','Concierge, ')+IIf(Skills.Skill_ISP Is Null,'','ISP, ')+IIf(Skills.Skill_Mada Is Null,'','Mada, ')+IIf(Skills.Skill_CSCS Is Null,'','CSCS, ')+'$',', $','') AS Skills FROM ((Agents INNER JOIN Resignation_Pool ON Agents.PF = Resignation_Pool.PF) LEFT JOIN Teams ON Agents.Team =  Teams.ID) LEFT JOIN Skills ON Agents.PF = Skills.PF WHERE Agents.Contract_Status = 'Active'

エラー:

塗りつぶし:SelectCommand.Connectionプロパティが初期化されていません。

コード:

            Dim SQL10 As New OleDb.OleDbCommand("SELECT Agents.[PF], Agents.[User_ID], Agents.[First_Name], Agents.[Second_Name], Agents.[Third_Name], Agents.[Family_Name], Agents.[Gender], Agents.[Contract_Type], Agents.Area, Teams.Team_Name, Agents.Hiring_Date, Resignation_Pool.Resignation_Date, Resignation_Pool.Effective_Date, " & Sql & " FROM ((Agents INNER JOIN Resignation_Pool ON Agents.PF = Resignation_Pool.PF) LEFT JOIN Teams ON Agents.Team =  Teams.ID) LEFT JOIN Skills ON Agents.PF = Skills.PF WHERE Agents.Contract_Status = 'Active'")
            Dim DataAdapter10 As New OleDb.OleDbDataAdapter(SQL10)
            Dim DataTable10 As New DataTable()
            DataAdapter10.Fill(DataTable10)
4

1 に答える 1

0

エラー メッセージは、OleDbDataAdapter に有効な接続に関連付けられた SelectCommand がないことを示しています。したがって、次のようにコードを変更する必要があります

  Using OleDbConnection connection = new OleDbConnection("your_connection_string")
      connection.Open
      Dim SQL10 As New OleDb.OleDbCommand("......", connection) ' add this to the OleDbCommand'
      Dim DataAdapter10 As New OleDb.OleDbDataAdapter(SQL10)
      Dim DataTable10 As New DataTable()
      DataAdapter10.Fill(DataTable10)
  End Using
于 2013-03-11T11:57:06.220 に答える