Difference between DataTable.Load() and DataTable = dataSet.Tables[];
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);
SQLite开发者_开发问答Command 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
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
精彩评论