How to save SELECT sql query results in an array in C# Asp.net

后端 未结 6 619
时光取名叫无心
时光取名叫无心 2020-12-14 17:36

I have wrote this query to get some results, if I want to save the results in an array what I have to do? I want to use the values which are in col1 and col2 in an IF state

6条回答
  •  被撕碎了的回忆
    2020-12-14 18:01

    A great alternative that hasn't been mentioned is to use the entity framework, which uses an object that is the table - to get data into an array you can do things like:

    var rows = db.someTable.SqlQuery("SELECT col1,col2 FROM  someTable").ToList().ToArray();
    

    for info on getting started with Entity Framework see https://msdn.microsoft.com/en-us/library/aa937723(v=vs.113).aspx

提交回复
热议问题