Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using MySql.Data.MySqlClient;
- namespace Applicatie
- {
- class Functions
- {
- public static MySqlConnection sqlConnector()
- {
- MySqlConnection sqlCs = null;
- try
- {
- string server = "server=" + Properties.Settings.Default.server + ";";
- string username = "uid=" + Properties.Settings.Default.username + ";";
- string password = "password=" + Properties.Settings.Default.password + ";";
- string database = "database=" + Properties.Settings.Default.databsae;
- //sqlCs = new MySqlConnection("server=localhost;database=dbname;uid=root;password=1255");
- sqlCs = new MySqlConnection(server + username + password + database);
- sqlCs.Open();
- }
- catch
- {
- //MessageBox.Show("Er ging iets fout tijdens het verbinden met de database", MessageBoxButtons.OK, MessageBoxIcon.Error);
- sqlCs = null;
- }
- return sqlCs;
- }
- public static int getArtikelID(MySqlConnection sqlCs, string ArtikelNaam)
- {
- int result = -1;
- try
- {
- MySqlCommand sqlCmd = sqlCs.CreateCommand();
- sqlCmd.CommandText = "SELECT artikel_id FROM producten WHERE omschrijving='" + ArtikelNaam + "'";
- result = Convert.ToInt32(sqlCmd.ExecuteScalar());
- }
- catch
- {
- result = -2;
- }
- return result;
- }
- }
- }
Add Comment
Please, Sign In to add comment