Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DataTable.Load()和DataTable=dataSet.Tables[]之间的差异;_C#_.net - Fatal编程技术网

C# DataTable.Load()和DataTable=dataSet.Tables[]之间的差异;

C# DataTable.Load()和DataTable=dataSet.Tables[]之间的差异;,c#,.net,C#,.net,我怀疑我是否使用以下代码从SQLlite数据库获取数据并将其加载到数据表中 SQLiteConnection cnn = new SQLiteConnection("Data Source=" + path); cnn.Open(); SQLiteCommand mycommand = new SQLiteCommand(cnn); string sql = "select Company,Phone,Email,Address,City,State,Zip,Country,Fax,Web

我怀疑我是否使用以下代码从SQLlite数据库获取数据并将其加载到数据表中

SQLiteConnection cnn = new SQLiteConnection("Data Source=" + path);

cnn.Open();

SQLiteCommand mycommand = new SQLiteCommand(cnn);
string sql = "select Company,Phone,Email,Address,City,State,Zip,Country,Fax,Web from RecordsTable";
mycommand.CommandText = sql;

SQLiteDataReader reader = mycommand.ExecuteReader();

dt.Load(reader);

reader.Close();

cnn.Close();
在某些情况下,当我尝试加载时,它会给出“无法启用约束异常”

但当我在下面尝试时,同一个表和同一组记录的给定代码就起作用了

SQLiteConnection ObjConnection = new SQLiteConnection("Data Source=" + path);

SQLiteCommand ObjCommand = new SQLiteCommand("select Company,Phone,Email,Address,City,State,Zip,Country,Fax,Web from RecordsTable", ObjConnection);
ObjCommand.CommandType = CommandType.Text;

SQLiteDataAdapter ObjDataAdapter = new SQLiteDataAdapter(ObjCommand);

DataSet dataSet = new DataSet();

ObjDataAdapter.Fill(dataSet, "RecordsTable");

dt = dataSet.Tables["RecordsTable"];
有谁能告诉我这两种方法之间的区别吗?Load()方法有目的地计算约束,而简单地按索引从数据集中拉出DataTable则没有。这就是你案件中的利益差异


请参阅:

听起来“Load”方法的SQLlite实现有一个bug。报告给我。在SQL Server版本中,“加载”方法也存在性能问题。请参阅,因此我在代码中没有使用它,以便在数据提供程序之间移动时保持一致。这是正确的答案,请参阅此注释以了解一些细节:以及