Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using entity framework for my database app where I need to run a query to my database using the app like this query
SQL
select top 1 * from table1 order by col1 desc, col3 asc


here my table1 has about four columns and I need to use all of those 4 columns in some other process for my app, I cant seem to get to pass all 4 column result to my variables at one time, normally i use a code like

C#
var col1= dbentity.Database.SqlQuery<string>(select col1 from table1 where col3=@param, new SqlParameter("param", param)).Single();


then i use col1 variable for my some other process. What i need is to run the select top 1 * from table1 and assign all the resulting columns to my variables.

Please help me with this. thanks in advance

(if ever this kind of question has already been answered a good reference link would be of big help :) )
Posted

You should check out the class DataAdapter and look for examples of how to use it.

http://msdn.microsoft.com/en-us/library/system.data.common.dataadapter(v=vs.110).aspx

Escpecially look at the method Fill.
 
Share this answer
 
Thanks for that insight George, though I was able to find a way that better suits me :) I used this page as reference http://geekswithblogs.net/dotNETvinz/archive/2011/04/04/entity-framework---fetching-and-populating-the-data-in-the.aspx[^] where adding a public class to define the columns, you could also use a raw sql query and still assign the resulting columns of a single row to any variables or controls that accept value.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900