簡體   English   中英

在C#OleDbDataAdapter.fill方法中沒有提供任何數據或錯誤

[英]in C# OleDbDataAdapter.fill method not giving any data or error

我正在使用數據適配器從訪問數據庫中提取數據(請參見下面的代碼)。 當我在Access數據庫中運行SQL時,我得到了預期的數據。 但是,當我單步執行代碼時,fill方法僅生成表定義,而沒有行。

過去,我已多次使用此過程,但對於那些調用它仍然有效。

再次,訪問中的SQL返回正確的數據,在C#中,我未收到任何錯誤消息,但我也未收到數據。 有人看過嗎?

`
公共無效的GetQueries(參考DataTable tSQL,字符串工具,字符串過濾器,OleDbConnection lConn){OleDbDataAdapter dadapt = new OleDbDataAdapter(); //訪問字符串的數據適配器lSQL =“”;

        //assign the connection to the processing mdb
        //lAccProcSQL.Connection = lConn;

        //Pull the queries to be executed
        lSQL = "SELECT * FROM tblSQL WHERE Active = TRUE AND ToolCode = '" +
            tool + "' and type not in (" + Filter + ") ORDER BY QueryNum";

        //Set the adapter to point to the tblSQL table
        dadapt = new OleDbDataAdapter(lSQL, lConn);

        //clear tables in case of rerun
        tSQL.Clear();

        //Fill working queries data table
        dadapt.Fill(tSQL);

    }`

您確定在WHERE子句中定義的過濾器在某些行上的計算結果為true嗎?

為什么不使用參數代替字符串連接? 您確定Active = True會評估為true嗎? 據我所知,True在Access中由-1表示。

所以,為什么不這樣嘗試呢?

var command = new OleDbCommand();
command.Connection = lConn;
command.CommandText = "SELECT * FROM tblSql WHERE Active = -1 AND ToolCode = @p_toolCode AND type NOT IN (" + filter + ") ORDER BY querynum";
command.Parameters.Add ("@p_toolCode", OleDbType.String).Value = tool;
datapt = new OleDbDataAdapter();
datapt.SelectCommand = command;
dadapt.Fill (tSql);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM