Guest User

Untitled

a guest
Jun 25th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using MySql.Data.MySqlClient;
  6.  
  7. namespace Applicatie
  8. {
  9.     class Functions
  10.     {
  11.         public static MySqlConnection sqlConnector()
  12.         {
  13.             MySqlConnection sqlCs = null;
  14.  
  15.             try
  16.             {
  17.                 string server = "server=" + Properties.Settings.Default.server + ";";
  18.                 string username = "uid=" + Properties.Settings.Default.username + ";";
  19.                 string password = "password=" + Properties.Settings.Default.password + ";";
  20.                 string database = "database=" + Properties.Settings.Default.databsae;
  21.  
  22.                 //sqlCs = new MySqlConnection("server=localhost;database=dbname;uid=root;password=1255");
  23.                 sqlCs = new MySqlConnection(server + username + password + database);
  24.                 sqlCs.Open();
  25.             }
  26.             catch
  27.             {
  28.                 //MessageBox.Show("Er ging iets fout tijdens het verbinden met de database", MessageBoxButtons.OK, MessageBoxIcon.Error);
  29.                 sqlCs = null;
  30.             }
  31.  
  32.             return sqlCs;
  33.         }
  34.  
  35.         public static int getArtikelID(MySqlConnection sqlCs, string ArtikelNaam)
  36.         {
  37.             int result = -1;
  38.  
  39.             try
  40.             {
  41.                 MySqlCommand sqlCmd = sqlCs.CreateCommand();
  42.                 sqlCmd.CommandText = "SELECT artikel_id FROM producten WHERE omschrijving='" + ArtikelNaam + "'";
  43.                 result = Convert.ToInt32(sqlCmd.ExecuteScalar());
  44.             }
  45.             catch
  46.             {
  47.                 result = -2;
  48.             }
  49.             return result;
  50.         }
  51.     }
  52. }
Add Comment
Please, Sign In to add comment