Skip to content

Commit

Permalink
added
Browse files Browse the repository at this point in the history
  • Loading branch information
Ezgi Yaman committed Oct 16, 2021
1 parent 039bdc8 commit 8e50632
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 49 deletions.
1 change: 1 addition & 0 deletions Dapper_Example/Dapper_Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Entities\Abstract\BaseEntity.cs" />
<Compile Include="Entities\Concretes\Categories.cs" />
<Compile Include="Entities\Concretes\Employees.cs" />
<Compile Include="Entities\Concretes\Products.cs" />
<Compile Include="Form1.cs">
Expand Down
16 changes: 16 additions & 0 deletions Dapper_Example/Entities/Concretes/Categories.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Dapper_Example.Entities.Abstract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dapper_Example.Entities.Concretes
{
public class Categories : BaseEntity
{
public int CategoryID { get; set; }
public string CategoryName { get; set; }
public string Description { get; set; }
}
}
71 changes: 37 additions & 34 deletions Dapper_Example/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 33 additions & 15 deletions Dapper_Example/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,53 @@ public Form1()
InitializeComponent();
}

public void EmployeesChoose()
private void btnExample_1_Click(object sender, EventArgs e)
{
using (IDbConnection connection = new SqlConnection("Server =DESKTOP-DF88VQJ;Database=Northwind;Integrated Security=True;"))
using (IDbConnection con = new SqlConnection("Server =DESKTOP-DF88VQJ;Database=Northwind;Integrated Security=True;"))
{
connection.Open();
List<Employees> employees = connection.Query<Employees>("Select * from Employees Where EmployeeID > 5 ").ToList();
con.Open();
List<Employees> employees = con.Query<Employees>("Select * from Employees Where EmployeeID > 5 ").ToList();
dataGridView1.DataSource = employees;
connection.Close();
con.Close();
}
}

private void btnExample_1_Click(object sender, EventArgs e)
private void btnExample_2_Click(object sender, EventArgs e)
{
EmployeesChoose();
using (IDbConnection con = new SqlConnection("Server =DESKTOP-DF88VQJ;Database=Northwind;Integrated Security=True;"))
{
con.Open();
List<Products> products = con.Query<Products>("Select Top 10 * from Products Where UnitPrice > 20 ").ToList();
dataGridView1.DataSource = products;
con.Close();
}
}

public void ProductChoose()
private void btnExample_3_Click(object sender, EventArgs e)
{
using (IDbConnection con = new SqlConnection("Server =DESKTOP-DF88VQJ;Database=Northwind;Integrated Security=True;"))
{
con.Open();
List<Employees> employees = con.Query<Employees>("Select * from Employees where YEAR(BirthDate)>=1950 and YEAR(BirthDate)<=1961").ToList();
dataGridView1.DataSource = employees;
con.Close();
}

}
private void btnExample_4_Click(object sender, EventArgs e)
{
using (IDbConnection connection = new SqlConnection("Server =DESKTOP-DF88VQJ;Database=Northwind;Integrated Security=True;"))

using (IDbConnection con = new SqlConnection("Server =DESKTOP-DF88VQJ;Database=Northwind;Integrated Security=True;"))
{
connection.Open();
List<Products> products = connection.Query<Products>("Select Top 10 * from Products Where UnitPrice > 20 ").ToList();
con.Open();
List<Products> products = con.Query<Products>("Select ProductID,ProductName,UnitsInStock from Products where (ProductName Like '[A-K]%')and(UnitsInStock between 5 and 40)").ToList();
dataGridView1.DataSource = products;
connection.Close();
con.Close();
}
}
private void btnExample_2_Click(object sender, EventArgs e)

private void btnExample_5_Click(object sender, EventArgs e)
{
ProductChoose();

}
}
}

0 comments on commit 8e50632

Please sign in to comment.