本文整理汇总了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);
}
}
示例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();
}
示例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_;
}
}
示例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;
}
}
示例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);
}
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
}