0

can i write somthing like this:

cmd = new OleDbCommand("select * from cmn_mst; select * from cmn_typ", oledbCon);

But this is showing an error. Is there any other way to write multiple select in dataset?

4 Answers 4

1

write a stored procedure, that outputs 2 ref cursors and call it in your .net code.

a detailed answer would need a knowledge in the type of provider your using.

But this should help google stuff.

This article might help.

Sign up to request clarification or add additional context in comments.

Comments

1

You can't do that in one OleDbCommand, you need to split the queries in two commands, so 2 datasets..

3 Comments

suppose when i write like new OleDbCommand("sp_cmn_mst", oledbCon); and sp_cm_mst is a storeprocedure returning 2 table.. then the dataset is containing 2 table data...
Ok, what is ther problem with that? You can access the two Datatables of the Dataset as easily as the Dataset itself.
i just wanted to make smaller in code... but from the above answers i got it is better to use SP
1

What is your reason of putting 2 queries in one dataset?

If you want to make it smaller in code, you may use views or stored procedure in you database.

Comments

0

Method 1

Try making this in two commands.

DataSet set1 = new DataSet();
using(OleDbDataAdapter adapter = new OleDbDataAdapter("select * from cmn_mst;", connection))
{
   adapter.Fill(set1);
}

DataSet set2 = new DataSet();
using(OleDbDataAdapter adapter = new OleDbDataAdapter("select * from cmn_typ;", connection))
{
   adapter.Fill(set2);
}

After Returning Two Dataset You can merge it into once

set1.EnforceConstraints = false;
set1.Merge(set2, true, MissingSchemaAction.AddWithKey);
set1.EnforceConstraints = true;
set1.AcceptChanges();

For further reference:

Method 2:

  • You have to write Stored Procedure and call it in your code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.