Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SP as Adapter SelectCommand
Message
 
To
14/12/2005 12:31:44
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 1.1
Database:
MS SQL Server
Miscellaneous
Thread ID:
01077893
Message ID:
01077939
Views:
41
Hmmm reading your post lights and sirens started going off. lol
My goal is (now) to only access my database using SPs. And come to think of it I have in a different app using a SP in the Adapter's SelectCommand (and in that app I also set the CommandType to SP <s>). Thanks for the wake-up post.


Now to the interesting question. Why am I using OleDbDataAdapter instead of SqlDataAdapter when my backend is MSSQL? The answer to that is what happends if one of my customers wants to use a different database backend? I haven't made up my mind if I should "force" the customers to use MSSQL yet. I am not even sure if I will test the app using any other database backend and specify that the app is only supported under MSSQL but the customer is free to attempt using a different database backend. Any thoughts on this?

Einar

>Of course you can use a Stored Procedure!!! Isn't that the only way to access your databases??? <g> (Preferred way anyway, IMHO).
>
>Anywho, you've almost got it right, but not quite. You need to also set the CommandType to be a Stored Proc. So, something like this:
>
>oleDbAdapter = new OleDbDataAdapter();
>oleDbAdapter .SelectCommand = new OleDbCommand("MyStoredProcedureName", oleDbConnection);
>oleDbAdapter .SelectCommand.CommandType = CommandType.StoredProcedure;
>oleDbAdapter .Fill(myDataset, "myTable");
>
>Also, I wonder why you're using OleDbDataAdapter ... isn't this a SQL database? If so, you should be using SqlDataAdapter and SqlCommand. If not, just ignore me. <g>
>
>~~Bonnie
>
>
>
>>>>I had a thought when I woke up this morning. Can I pass a SP as an Adapter's SelectCommand?
>>>>If it is possible are there any advantages/disadvantages for doing this?
>>>>
>>>>Einar
>>>
>>>I may not understand your question but here is something that I do.
>>>
>>>I have a Class that controls my data handling. When I use a DataAdapter I call a SP. Now as for advantages/disadvantages, I am guessing that allowing the SP to do “the work” would be better.
>>
>>I think you understand my question.
>>This is in a nut-shell what I want to do:
>>
>>oleDbAdapter = new OleDbDataAdapter();
>>oleDbAdapter.SelectCommand = new OleDbCommand("MyStoredProcedureName", oleDbConnection);
>>oleDbAdapter.Fill(myDataset, "myTable");
>>
>>
>>I realize how easy it would be for me to test this, but I just wanted to check here before I dove into that.
>>
>>Einar
Semper ubi sub ubi.
Previous
Reply
Map
View

Click here to load this message in the networking platform