Code Monkey home page Code Monkey logo

csharpdb's Introduction

Documentation.

This reference will help you to handle your database easily and quickly.
  1. Download DLL reference DBmanager and add it into your refernces.
  2. Add namespace using DBmanager
  3. Initialize your Connection string.
DB.MConnectionString = "Your connection";

Now you can use this class everywhere in your project like these example.

Table users


ID fName lName email country
1 Mohammed Hamham [email protected] Morocco
2 Thomas Aubry [email protected] France
3 Benard Perret [email protected] Spain
4 Jamal Bensaad [email protected] Morocco
5 Rachid Ettouti [email protected] Egypt



Insert new user


  private void button_Click(object sender, EventArgs e)
  {
    DB.MParam.Add("ID", 6);
    DB.MParam.Add("fName", "Kamal");
    DB.MParam.Add("lName", "Nassiri");
    DB.MParam.Add("email", "[email protected]");
    DB.MParam.Add("country", "Libya");
    
    DB.Insert("users");
  }
Result
ID fName lName email country
1 Mohammed Hamham [email protected] Morocco
2 Thomas Aubry [email protected] France
3 Benard Perret [email protected] Spain
4 Jamal Bensaad [email protected] Morocco
5 Rachid Ettouti [email protected] Egypt
6 Kamal Nassiri [email protected] Libya



Delete user


  private void button_Click(object sender, EventArgs e)
  {
    DB.Delete("users","ID=1");
    DB.Delete("users", "fName='Benard'");
    DB.Delete("users", "country='Egypt'");
  }
Result
ID fName lName email country
2 Thomas Aubry [email protected] France
4 Jamal Bensaad [email protected] Morocco



Update users


  private void button_Click(object sender, EventArgs e)
  {
    // First update
    DB.MParam.Add("ID", 10);
    DB.MParam.Add("fName", "Karim");
    DB.MParam.Add("lName", "Khoumani");
    DB.Update("users", "ID=2");
    
    // Second update
    DB.MParam.Add("ID", 60);
    DB.MParam.Add("fName", "Yassine");
    DB.MParam.Add("lName", "Rachidi");
    DB.Update("users", "country='Spain'");
  }
Result
ID fName lName email country
1 Mohammed Hamham [email protected] Morocco
10 Karim Khoumani [email protected] France
60 Yassine Rachidi [email protected] Spain
4 Jamal Bensaad [email protected] Morocco
5 Rachid Ettouti [email protected] Egypt



Select all


  private void button_Click(object sender, EventArgs e)
  {
    DB.Select("users");
  }
Result
ID fName lName email country
1 Mohammed Hamham [email protected] Morocco
2 Thomas Aubry [email protected] France
3 Benard Perret [email protected] Spain
4 Jamal Bensaad [email protected] Morocco
5 Rachid Ettouti [email protected] Egypt



Select specific columns


  private void button_Click(object sender, EventArgs e)
  {
    DB.Select("users","fName, lName");
  }
Result
fName lName
Mohammed Hamham
Thomas Aubry
Benard Perret
Jamal Bensaad
Rachid Ettouti



Search in all columns


  private void button_Click(object sender, EventArgs e)
  {
    var textBox = "Jama";
    DB.Select("users","*",$"fName LIKE %{ textBox }% OR lName LIKE %{ textBox }% OR email LIKE %{ textBox }% OR country LIKE %{ textBox }%");
  }
Result
ID fName lName email country
4 Jamal Bensaad [email protected] Morocco



Multi search


  private void button_Click(object sender, EventArgs e)
  {
    var fn = "Rachi";
    var ln = "Ettouti";
    var em = "rettouti";
    var co = "gyp";
    DB.Select("users","fName, email",$"fName LIKE %{ fn }% AND lName LIKE %{ ln }% AND email LIKE %{ em }% AND country LIKE %{ co }%");
  }
Result
fName email
Rachid [email protected]



Get number of rows


  private void button_Click(object sender, EventArgs e)
  {
    var count = DB.Select("users").Rows.Count;
    MessageBoxshow(count.ToString());  
  }
Result

Alert with number of rows 5



Example login


var textBoxEmail    = "[email protected]";
var textBoxPassword = 123;

var user = DB.Select("users", "*", $"columnEmail={ textBoxEmail } && columnPassword={ textBoxPassword }");
if(user.Rows.Count > 0)
{
    MessageBox.Show("Welcome");
}
else
{
    MessageBox.Show("Email or password incorrect");
}

Author

License

Copyright © 2021, Mohamed Hamham. Released under the MIT License.

csharpdb's People

Contributors

dvhamham avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.