Reading values from SQL database in C#

前端 未结 5 992
陌清茗
陌清茗 2020-12-14 01:45

i have just started learning C# and i can write data to the database without a problem. But i\'m having problems with reading, the SQL executes fine but i\'m having issues w

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 02:26

    Personally I'd write a class with 4 properties (with matching names and types), then use "dapper" (http://code.google.com/p/dapper-dot-net/):

    var data = connection.Query(
        "select * from Requests where Complete = 0").ToList();
    

    With something like:

    public class Request {
        public string Username{get;set;}
        ...
        public bool Complete {get;set;}
    }
    

    Dapper is free, simple, has parameterisation to avoid SQL-injection, and is very very fast.

提交回复
热议问题