returning a datareader
-
Hello! I want to create a method that connects to a sql db and retrives some values. I want the connection in a method so I can reuse the code. My question is if I can return a data in the same way you return a string or int? And how do i do this?
-
Hello! I want to create a method that connects to a sql db and retrives some values. I want the connection in a method so I can reuse the code. My question is if I can return a data in the same way you return a string or int? And how do i do this?
_Searcher_ wrote: My question is if I can return a data in the same way you return a string or int? Yes _Searcher_ wrote: And how do i do this? For example:
public DataReader MyMethod()
{
DataReader dr = myCommand.ExecuteDataReader();
return dr;
}Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar The Second EuroCPian Event will be in Brussels on the 4th of September
-
Hello! I want to create a method that connects to a sql db and retrives some values. I want the connection in a method so I can reuse the code. My question is if I can return a data in the same way you return a string or int? And how do i do this?
Well the earlier response I guess answers your question. I just would like to add that you may go through Microsoft Data Application Block(downloadable from Microsoft site) and use their ready made methods to connect to database and retrieve or insert data. It is damn simple to use and very very efficient... believe me... and lines of code???... Imagine writing just 2 lines of code to retrieve data from database... To give you a picture... the application block manages the connection... you only need to supply the query... Cheers... Aryadip. Cheers !! and have a Funky day !!
-
Well the earlier response I guess answers your question. I just would like to add that you may go through Microsoft Data Application Block(downloadable from Microsoft site) and use their ready made methods to connect to database and retrieve or insert data. It is damn simple to use and very very efficient... believe me... and lines of code???... Imagine writing just 2 lines of code to retrieve data from database... To give you a picture... the application block manages the connection... you only need to supply the query... Cheers... Aryadip. Cheers !! and have a Funky day !!
Thanks so much for the answers! It worked out great. I didnt try the data application block, but I will look in to that later!