-
Notifications
You must be signed in to change notification settings - Fork 0
/
SqlServerShort.cs
56 lines (52 loc) · 1.89 KB
/
SqlServerShort.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Theater
{
class SqlServerShort
{
/* Переменные */
private SqlConnection _connection;
private SqlCommand _command;
private String _sqlCommand;
/* Конструктор */
public SqlServerShort()
{
_connection = new SqlConnection();
//_connection.ConnectionString = "server=SOMOV-PC\\SQLEXPRESS;uid=sa;password=12345;database=theater";
_connection.ConnectionString = "server=" + ConnectConfig.server + ";uid=" + ConnectConfig.uid + ";password=" + ConnectConfig.password + ";database=" + ConnectConfig.database;
_command = new SqlCommand("", _connection);
}
/* свойства */
public String SqlCommand
{
get { return _sqlCommand; }
set { _sqlCommand = value; }
}
/* Методы */
public bool ExecuteNonQuery()
{
try
{
_connection.Open();
_command.CommandText = _sqlCommand;
_command.ExecuteNonQuery(); //выполнение запроса
_connection.Close();
return true;
}
catch (Exception ex)
{
_connection.Close();
if (MessageBox.Show("Ошибка выполнения SQL запроса." + System.Environment.NewLine + "Показать полное сообщение?", "Ошибка:", MessageBoxButtons.YesNo) == DialogResult.Yes) //Сообщение об ошибке
{
MessageBox.Show(ex.ToString());
}
return false; //произошла ошибка.
}
}
}
}