retrieve two tables of data at a time by using data reader
One interview I faced a Q: how can i retrieve two tables of data at a time by using data reader? Data reader read and forward only, how is
it possible to get 2 tables of data at a time
Hi, If we execute 2 select command either in stored procedure or in select command and then executereader method fired of command object. it return 2 tables in datareader.
like : string str="Select * from a;select * from b"; cmd.commandtext=str; dr=cmd.executereader();
RE: retrieve two tables of data at a time by using dat...
Hi If we execute 2 select command either in stored procedure or in select command and then executereader method fired of command object. it return 2 tables in datareader.
like : string str "Select * from a;select * from b"; cmd.commandtext str; dr cmd.executereader();
RE: retrieve two tables of data at a time by using data reader
For the following code
---------------------------------------- objCmd.CommandText "SELECT * FROM [Categories];SELECT * FROM [Customers];"; objRdr objCmd.ExecuteReader(); ----------------------------------------
It Keeps throwing the following exception ----------------------- System.Data.OleDb.OleDbException: Characters found after end of SQL statement. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.OleDb.OleDbCommand.ExecuteReader() -----------------------
RE: retrieve two tables of data at a time by using data reader
Yes this possiable to retreive the data from tw tables useing datareader syntax: in sql select * from EmployeeMaster Department sqlcommaned cmd new sqlcommaned (); cmd.commanedText "select * from EmployeeMaster Department"; sqldatareader dr cmd.ExecuteReader();
RE: retrieve two tables of data at a time by using data reader
This is absolutely true that theoretically you can't access two resultset concurrently using Datareader due to its nature of having the connection state with database and forward only traversing. However if it is possible to have the data from two tables using some manipulation in the "Select" Query so that the desired resultset is achieved. If one uses Union/Union All he/she has to be very careful regarding the select phrase in both sub-queries.
RE: retrieve two tables of data at a time by using data reader
Better use joins like Select field1 field2 field3 from table1 inner join table2 on table1.fieldx table2.fieldx field1 filed2 are from first table field3 from second table fieldx is common field from both table.