4

I have a doubt i use the following piece of code get data from a SQLlite data base and Load it into a data table

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

In some cases when I try to load it Gives me "Failed to enable constraints exception"

But when I tried this below given piece of code for same table and same set of records it worked

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"];

Can any one tell me what is the difference between two

ChrisF
  • 134,786
  • 31
  • 255
  • 325
subbu
  • 3,229
  • 13
  • 49
  • 70
  • Sounds like the SQLlite implementation of the "Load" method has a bug. Report it to http://sourceforge.net/projects/adodotnetsqlite/. In the SQL Server edition the "Load" method also has performance issues. See https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=95318&wa=wsignin1.0, so I've not used it in my code, for consistance when moving between data providers. – Jamie Clayton Jun 16 '10 at 22:22

1 Answers1

5

The Load() method purposefully evaluates constraints, whereas simply pulling out a DataTable from the Dataset by index does not. That's the difference of interest in your case.

See: http://msdn.microsoft.com/en-us/library/hsze9wte(VS.80).aspx

btt
  • 422
  • 6
  • 16
  • That's the correct answer, see this comment for some insight: http://stackoverflow.com/questions/6073382/read-sql-table-into-c-sharp-datatable/14807940#comment35409117_14807940 and this http://stackoverflow.com/questions/229425/net-datatable-skips-rows-on-loaddatareader – nawfal Jun 11 '15 at 10:20