Multiple Select Statements in DataAdapter
-
Can i write Multiple Select Statements in DataAdapter . If it is Possible means How to write ? I have written like this but it is throwing the error. DataAdapter=new OleDbDataAdapter("select * from Table1;select * from Table2",connection);
VanithaVasu
-
Can i write Multiple Select Statements in DataAdapter . If it is Possible means How to write ? I have written like this but it is throwing the error. DataAdapter=new OleDbDataAdapter("select * from Table1;select * from Table2",connection);
VanithaVasu
No u canot write like this.. u can use join querry
Sarith...
-
Can i write Multiple Select Statements in DataAdapter . If it is Possible means How to write ? I have written like this but it is throwing the error. DataAdapter=new OleDbDataAdapter("select * from Table1;select * from Table2",connection);
VanithaVasu
VanithaVasu wrote:
Can i write Multiple Select Statements in DataAdapter .
Yes you can. When you fill dataset, it will contain two datatables. But instead of separating multiple queries with ; symbol, it's better to go for store procedure's.
VanithaVasu wrote:
I have written like this but it is throwing the error. DataAdapter=new OleDbDataAdapter("select * from Table1;select * from Table2",connection);
What's the error it's throwing ?
-
VanithaVasu wrote:
Can i write Multiple Select Statements in DataAdapter .
Yes you can. When you fill dataset, it will contain two datatables. But instead of separating multiple queries with ; symbol, it's better to go for store procedure's.
VanithaVasu wrote:
I have written like this but it is throwing the error. DataAdapter=new OleDbDataAdapter("select * from Table1;select * from Table2",connection);
What's the error it's throwing ?
The Error is : Characters found after end of SQL statement. I want to the two tables separately in my dataset. How to do so?
VanithaVasu
-
The Error is : Characters found after end of SQL statement. I want to the two tables separately in my dataset. How to do so?
VanithaVasu
What is it that you are after? If you want more than two select statements in the table use a join. If you want different select statements for different tables or adapters, use different querystrings... I think for ur case u need : DataTable dt1=new DataTable(); DataTable dt2=new DataTable(); dt1="first sql select query result"; dt2="second sql select query result"; dataset ds=new dataset(); ds.Tables.Add(dt1); ds.Tables.Add(dt2); Hope that helps!!!
I was born dumb!! :laugh:Programming made me laugh:laugh:!!! --sid--
-
The Error is : Characters found after end of SQL statement. I want to the two tables separately in my dataset. How to do so?
VanithaVasu
Insetd of trying this: DataAdapter=new OleDbDataAdapter("select * from Table1;select * from Table2",connection); Try this: SqlDataAdapter adpt1 = new SqlDataAdapter("Select * From Table1", con); DataSet ds = new DataSet(); adpt1.Fill(ds); SqlDataAdapter adpt2 = new SqlDataAdapter("Select * From Table2", con); adpt2.Fill(ds); return ds;
Naresh Patel
-
The Error is : Characters found after end of SQL statement. I want to the two tables separately in my dataset. How to do so?
VanithaVasu
VanithaVasu wrote:
I want to the two tables separately in my dataset. How to do so?
As I told before, stored procedure's would be better approach for your problem. Write a stored procedure like
CREATE PROCEDURE [dbo].[MultipleSelect]
AS
SELECT * FROM FisrtTable
SELECT * FROM SecondTableGO
Now Set command type to stored procedures for your OleDbCommand. Pass this stored procedures and fill dataset. This will give you two tables in dataset. Returning multiple recordset is a recommended practice by MSDN, which boosts performance.