当前位置: 首页>>代码示例>>C#>>正文


C# System.Data.SqlClient.SqlConnection.Query方法代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlConnection.Query方法的典型用法代码示例。如果您正苦于以下问题:C# System.Data.SqlClient.SqlConnection.Query方法的具体用法?C# System.Data.SqlClient.SqlConnection.Query怎么用?C# System.Data.SqlClient.SqlConnection.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.SqlConnection的用法示例。


在下文中一共展示了System.Data.SqlClient.SqlConnection.Query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetCategoryList

 /// <summary>
 /// 获取权限类别的列表
 /// </summary>        
 public object GetCategoryList()
 {
     using (var conn = new System.Data.SqlClient.SqlConnection(ConnString))
     {
         return conn.Query<AccountsPermissionCategories>("sp_Accounts_GetPermissionCategories", null, null, true, null, CommandType.StoredProcedure);
     }
 }
开发者ID:wangliang1983821,项目名称:wl_Users_Accounts,代码行数:10,代码来源:PermissionCategory.cs

示例2: Main

        public static void Main(string[] args)
        {
            try
            {
                using (var connection = new System.Data.SqlClient.SqlConnection(ConnectionString))
                {
                    connection.Open();

                    var sql = "select * FROM People";

                    var people = connection.Query<People>(sql);

                    foreach (var person in people)
                    {
                        Console.WriteLine(JsonConvert.SerializeObject(person));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.StackTrace);
            }

            Console.ReadLine();
        }
开发者ID:laball,项目名称:demo,代码行数:25,代码来源:Program.cs

示例3: GetEvents

 public IEnumerable<EventModel> GetEvents()
 {
     using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
     {
         sqlConnection.Open();
         var event_ = sqlConnection.Query<EventModel>("SELECT * FROM Event");
         return event_;
     }
 }
开发者ID:spikemcfarland,项目名称:CLIMB,代码行数:9,代码来源:EventDB.cs

示例4: GetRelatedEvents

 public IEnumerable<EventModel> GetRelatedEvents(int eventKey)
 {
     using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
     {
         sqlConnection.Open();
         var animal = sqlConnection.Query<EventModel>("SELECT * FROM Event WHERE _Event_key IN (SELECT _RelatedEvent_key FROM EventMap WHERE _Event_key={0})", eventKey);
         return animal;
     }
 }
开发者ID:spikemcfarland,项目名称:CLIMB,代码行数:9,代码来源:EventDB.cs

示例5: GetPermissionsInCategory

 /// <summary>
 /// 获取指定类别下的权限列表
 /// </summary>        
 public object GetPermissionsInCategory(int categoryId)
 {
     DynamicParameters p = new DynamicParameters();
     p.Add("@CategoryID", categoryId, DbType.Int32);
     using (var conn = new System.Data.SqlClient.SqlConnection(ConnString))
     {
         return conn.Query<AccountsPermissionCategories>("sp_Accounts_GetPermissionsInCategory", p, null, true, null, CommandType.StoredProcedure);
     }
 }
开发者ID:wangliang1983821,项目名称:wl_Users_Accounts,代码行数:12,代码来源:PermissionCategory.cs

示例6: Retrieve

        /// <summary>
        /// 获取权限类别信息
        /// </summary>        
        public object Retrieve(int categoryId)
        {
            using (var conn = new System.Data.SqlClient.SqlConnection(ConnString))
            {

                return conn.Query<AccountsPermissionCategories>("sp_Accounts_GetPermissionCategoryDetails", new { CategoryID = categoryId }, null, true, null, CommandType.StoredProcedure).SingleOrDefault();

            }
        }
开发者ID:wangliang1983821,项目名称:wl_Users_Accounts,代码行数:12,代码来源:PermissionCategory.cs

示例7: GetWorkers

        public IEnumerable<Worker> GetWorkers(int usersID = 0)
        {
            System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring);

            sqlConnection.Open();
            var worker = sqlConnection.Query<Worker>("dbo.spUsersGet "+usersID.ToString());
            sqlConnection.Close();
            return worker;
        }
开发者ID:KYJIBEPCTYKAC,项目名称:moedelo,代码行数:9,代码来源:WorkerDB.cs

示例8: Retrieve

        /// <summary>
        /// 根据角色ID获取角色的信息
        /// </summary>
        public object Retrieve(int roleId)
        {
            using (var conn = new System.Data.SqlClient.SqlConnection(ConnString))
            {

                return conn.Query<AccountsRoles>("sp_Accounts_GetRoleDetails", new { RoleID = roleId }, null, true, null, CommandType.StoredProcedure).SingleOrDefault();

            }

        }
开发者ID:wangliang1983821,项目名称:wl_Users_Accounts,代码行数:13,代码来源:Role.cs

示例9: GetCustomers

        public IEnumerable<Customer> GetCustomers()
        {
            using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
            {
                sqlConnection.Open();
                var customer = sqlConnection.Query<Customer>("sELECT * FROM Customer");
                return customer;

            }
        }
开发者ID:xi33,项目名称:DapperMVC,代码行数:10,代码来源:CustomerDB.cs

示例10: GetMaterialTypes

        public IEnumerable<MaterialTypeModel> GetMaterialTypes()
        {
            using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
            {
                sqlConnection.Open();
                var materialTypes = sqlConnection.Query<MaterialTypeModel>("SELECT * FROM cv_MaterialType");
                return materialTypes;

            }
        }
开发者ID:spikemcfarland,项目名称:CLIMB,代码行数:10,代码来源:CvDB.cs

示例11: GetCustomerById

 public Customer GetCustomerById(int customerId)
 {
     using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
     {
         sqlConnection.Open();
         string sqlQuery = string.Format("SELECT * FROM Customer WHERE CustomerId = @Id");
         var customer = sqlConnection.Query<Customer>(sqlQuery, new {Id = customerId}).SingleOrDefault();
         return customer;
     }
 }
开发者ID:xi33,项目名称:DapperMVC,代码行数:10,代码来源:CustomerDB.cs

示例12: GetEventMaterials

        public MaterialModel GetEventMaterials(int eventKey)
        {
            using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
            {
                sqlConnection.Open();
                string strQuery = string.Format("SELECT * FROM Material WHERE _Material_key IN (SELECT _Material_key FROM EventMaterial WHERE _Event_key={0}", eventKey);
                var animal = sqlConnection.Query<MaterialModel>(strQuery).Single<MaterialModel>();
                return animal;

            }
        }
开发者ID:spikemcfarland,项目名称:CLIMB,代码行数:11,代码来源:MaterialDB.cs

示例13: GetdynPostsByTag

        //This is the Dapper Version
        public TagCount GetdynPostsByTag(string tagname)
        {
            string connection = ConfigurationManager.ConnectionStrings["SoFConnStr"].ToString();
            int counter;

            using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(connection))
            {
                sqlConnection.Open();
                counter = sqlConnection.Query<int>("SELECT Count(0) as PostCount FROM dbo.Posts WHERE FREETEXT(tags, @tagname)", new { tagname = tagname }).Single();
            }
                TagCount taggy = new TagCount { TagName = tagname, CountTag = counter };
            return taggy;
        }
开发者ID:datachomp,项目名称:StackOverFaux,代码行数:14,代码来源:SqlTagRepository.cs

示例14: AddGame

        public game AddGame(game myGame)
        {
            using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
            {
                sqlConnection.Open();
                myGame.game_id = sqlConnection.Query<int>(@"insert into game (A1, A2, A3, B1, B2 , B3 , C1, C2, C3 ,status , winner)
                                        values(@A1, @A2,@A3,  @B1, @B2, @B3,  @C1, @C2,  @C3,@status, @winner);
                                        SELECT CAST(SCOPE_IDENTITY() AS INT)",
                    new
                    {
                        A1 = myGame.A1,
                        A2 = myGame.A2,
                        A3 = myGame.A3,
                        B1 = myGame.B1,
                        B2 = myGame.B2,
                        B3 = myGame.B3,
                        C1 = myGame.C1,
                        C2 = myGame.C2,
                        C3 = myGame.C3,
                        status = myGame.status,
                        winner = myGame.winner,
                        gameid = myGame.game_id,

                    }).Single();

                sqlConnection.Close();
            }
            using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
            {
                sqlConnection.Open();
                sqlConnection.Query<int>(@"insert into players (game_id,user_one_id,user_two_id)
                                                            values(@gameid,@userOneId,@userTwoId);",
                    new
                    {
                        gameid = myGame.game_id,
                        userOneId = myGame.user_one_id,
                        userTwoId = myGame.user_two_id
                    }).Single();

                sqlConnection.Close();
            }
            return myGame;
        }
开发者ID:bamba,项目名称:tic,代码行数:43,代码来源:GameModel.cs

示例15: GetUserById

 public user GetUserById(int id)
 {
     using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
     {
         sqlConnection.Open();
         user usr = sqlConnection.Query<user>(@"select * from user where user_id = @userid", new { userid = id }).First();
         sqlConnection.Close();
         return usr;
     }
 }
开发者ID:bamba,项目名称:tic,代码行数:10,代码来源:GameModel.cs


注:本文中的System.Data.SqlClient.SqlConnection.Query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。