Simple use of dapper (beginner induction)

Source: Internet
Author: User

Simple use of dapper (beginner induction)

Reference:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Data;
Using System.Data.SqlClient;
Using System.Configuration;
Using Model;
Using Dapper;


Establishing a database connection
public static SqlConnection Sqlconn ()
{
String connstring = configurationmanager.connectionstrings["ConnString"]. ConnectionString;
var conntion = new SqlConnection (connstring);
Conntion. Open ();
return conntion;
}

List
Public list<user> GetList ()
{
using (idbconnection con = userdal.sqlconn ())
{
String Sqlcommandtex = "SELECT * from Tb_user";
List<user> userlist = Sqlmapper.query<user> (Con, Sqlcommandtex). ToList ();
return userlist;
}
}

Delete
public int del (int id)
{
using (idbconnection con = userdal.sqlconn ())
{
String comm = "Delete from Tb_user where id = @id";

int res = con. Execute (comm, new {id = id});
return res;
}
}

Parameter list
Public User GetUser (int id)
{
using (idbconnection con = userdal.sqlconn ())
{
String sql = "SELECT * from Tb_user where [email protected]";
User q = con. query<user> (SQL, new {id = id}). Singleordefault ();
return q;
}
}

Modify
public int UPD (User QQ)
{
using (idbconnection con = userdal.sqlconn ())
{
String sql = "Update tb_user set [email protected],[email protected],[email protected] where [email protected]";
int q = con. Execute (SQL, QQ);
return q;
}
}

Simple use of dapper (beginner induction)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.