簡體   English   中英

Datatable.Load不適用於SqlCeReader

[英]Datatable.Load does not work with SqlCeReader

我有這種方法:

public static DataTable ExecuteDataTable(IDbConnection connection, string cmdText)
{
    IDbCommand command = connection.CreateCommand();
    command.CommandText = cmdText;
    command.CommandType = CommandType.Text;
    IDataReader reader = command.ExecuteReader();
    DataTable dt = new DataTable();
    dt.Load(reader);
    return dt;
}

當我執行查詢時, select * from information_schema.Tables類型為SQLConnection的連接中select * from information_schema.Tables 但是,當我嘗試針對SqlCEConnection類型的連接運行它時, dt.Load(reader)會引發異常:

System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

當然是一個奇怪的問題,但這是一個替代方案:

將數據讀入DataSet並將EnforceConstraints設置為false。 然后,您可以返回DataSet.Tables[0]

暫無
暫無

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

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