Форум программистов, компьютерный форум, киберфорум
C++/CLI Windows Forms
Войти
Регистрация
Восстановить пароль
Блоги Сообщество Поиск Заказать работу  
 
1 / 1 / 0
Регистрация: 06.01.2015
Сообщений: 13

Почти сделал БД(база данных). Не определены некоторые идентификаторы

20.11.2015, 19:45. Показов 517. Ответов 1
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
Делал по методичке Культина.
C++
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#pragma once
namespace Ex1 {
 
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
 
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            int w = 0;
            for (int i = 0; i < listView1->Columns->Count; i++)
            {
                w += listView1->Columns[i]->Width;
            }
 
            if (listView1->BorderStyle == BorderStyle::Fixed3D)
                w += 4;
 
            listView1->Width = w + 17;
        }
 
    protected:
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::ListView^  listView1;
    protected:
    private: System::Windows::Forms::TextBox^  textBox1;
    private: System::Windows::Forms::TextBox^  textBox2;
    private: System::Windows::Forms::TextBox^  textBox3;
    private: System::Windows::Forms::TextBox^  textBox4;
    private: System::Windows::Forms::Button^  button1;
    private: System::Windows::Forms::Button^  button2;
    private: System::Windows::Forms::Button^  button3;
    private: System::Windows::Forms::Button^  button4;
    private: System::Windows::Forms::Label^  label1;
    private: System::Windows::Forms::Label^  label2;
    private: System::Windows::Forms::Label^  label3;
    private: System::Windows::Forms::ColumnHeader^  columnHeader1;
    private: System::Windows::Forms::ColumnHeader^  columnHeader2;
    private: System::Windows::Forms::ColumnHeader^  columnHeader3;
    private: System::Windows::Forms::ColumnHeader^  columnHeader4;
 
    private: void ShowDB()
    {
        SqlCeEngine^ engine = gcnew SqlCeEngine("Data Source='contacts.sdf';");
        SqlCeConnection^ connection = gcnew SqlCeConnection(engine->LocalConnectionString);
        connection->Open();
        SqlCeCommand^ command = connection->CreateCommand();
        command->CommandText ="SELECT * FROM contacts ORDER BY name";
        SqlCeDataReader^ dataReader = command->ExecuteReader();
        String^ st; // значение поля БД
        int itemIndex = 0;
        listView1->Items->Clear();
        while (dataReader->Read())
        {
                for (int i = 0; i < dataReader->FieldCount; i++)
                {
                    st = dataReader->GetValue(i)->ToString();
                    switch (i)
                    {
                    case 0: // поле cid
                        listView1->Items->Add(st);
                        break;
                    case 1: // поле name
                        listView1->Items[itemIndex]->SubItems->Add(st);
                        break;
                    case 2: // поле phone
                        listView1->Items[itemIndex]->SubItems->Add(st);
                        break;
                    case 3: // поле email
                        listView1->Items[itemIndex]->SubItems->Add(st);
                        break;
                    };
                }
            itemIndex++;
        }
        connection->Close();
    }
 
    private:
        /// <summary>
        /// Требуется переменная конструктора.
        /// </summary>
        System::ComponentModel::Container ^components;
 
#pragma region Windows Form Designer generated code
        /// <summary>
        /// Обязательный метод для поддержки конструктора - не изменяйте
        /// содержимое данного метода при помощи редактора кода.
        /// </summary>
        void InitializeComponent(void)
        {
            this->listView1 = (gcnew System::Windows::Forms::ListView());
            this->columnHeader1 = (gcnew System::Windows::Forms::ColumnHeader());
            this->columnHeader2 = (gcnew System::Windows::Forms::ColumnHeader());
            this->columnHeader3 = (gcnew System::Windows::Forms::ColumnHeader());
            this->columnHeader4 = (gcnew System::Windows::Forms::ColumnHeader());
            this->textBox1 = (gcnew System::Windows::Forms::TextBox());
            this->textBox2 = (gcnew System::Windows::Forms::TextBox());
            this->textBox3 = (gcnew System::Windows::Forms::TextBox());
            this->textBox4 = (gcnew System::Windows::Forms::TextBox());
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->button2 = (gcnew System::Windows::Forms::Button());
            this->button3 = (gcnew System::Windows::Forms::Button());
            this->button4 = (gcnew System::Windows::Forms::Button());
            this->label1 = (gcnew System::Windows::Forms::Label());
            this->label2 = (gcnew System::Windows::Forms::Label());
            this->label3 = (gcnew System::Windows::Forms::Label());
            this->SuspendLayout();
            // 
            // listView1
            // 
            this->listView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::ColumnHeader^  >(4) {
                this->columnHeader1, this->columnHeader2,
                    this->columnHeader3, this->columnHeader4
            });
            this->listView1->FullRowSelect = true;
            this->listView1->GridLines = true;
            this->listView1->HideSelection = false;
            this->listView1->Location = System::Drawing::Point(13, 13);
            this->listView1->MultiSelect = false;
            this->listView1->Name = L"listView1";
            this->listView1->Size = System::Drawing::Size(646, 212);
            this->listView1->TabIndex = 0;
            this->listView1->UseCompatibleStateImageBehavior = false;
            this->listView1->View = System::Windows::Forms::View::Details;
            this->listView1->ItemSelectionChanged += gcnew System::Windows::Forms::ListViewItemSelectionChangedEventHandler(this, &Form1::listView1_ItemSelectionChanged);
            // 
            // columnHeader1
            // 
            this->columnHeader1->Text = L"cid";
            this->columnHeader1->Width = 35;
            // 
            // columnHeader2
            // 
            this->columnHeader2->Text = L"Имя";
            this->columnHeader2->Width = 130;
            // 
            // columnHeader3
            // 
            this->columnHeader3->Text = L"Телефон";
            this->columnHeader3->Width = 110;
            // 
            // columnHeader4
            // 
            this->columnHeader4->Text = L"E-mail";
            this->columnHeader4->Width = 110;
            // 
            // textBox1
            // 
            this->textBox1->Location = System::Drawing::Point(94, 248);
            this->textBox1->Name = L"textBox1";
            this->textBox1->Size = System::Drawing::Size(150, 20);
            this->textBox1->TabIndex = 1;
            this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
            // 
            // textBox2
            // 
            this->textBox2->Location = System::Drawing::Point(94, 274);
            this->textBox2->Name = L"textBox2";
            this->textBox2->Size = System::Drawing::Size(150, 20);
            this->textBox2->TabIndex = 2;
            this->textBox2->TextChanged += gcnew System::EventHandler(this, &Form1::textBox2_TextChanged);
            // 
            // textBox3
            // 
            this->textBox3->Location = System::Drawing::Point(94, 300);
            this->textBox3->Name = L"textBox3";
            this->textBox3->Size = System::Drawing::Size(150, 20);
            this->textBox3->TabIndex = 3;
            this->textBox3->TextChanged += gcnew System::EventHandler(this, &Form1::textBox3_TextChanged);
            // 
            // textBox4
            // 
            this->textBox4->Location = System::Drawing::Point(282, 248);
            this->textBox4->Name = L"textBox4";
            this->textBox4->ReadOnly = true;
            this->textBox4->Size = System::Drawing::Size(150, 20);
            this->textBox4->TabIndex = 4;
            // 
            // button1
            // 
            this->button1->Location = System::Drawing::Point(282, 274);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(65, 20);
            this->button1->TabIndex = 5;
            this->button1->Text = L"Добавить";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
            // 
            // button2
            // 
            this->button2->Location = System::Drawing::Point(367, 274);
            this->button2->Name = L"button2";
            this->button2->Size = System::Drawing::Size(65, 20);
            this->button2->TabIndex = 6;
            this->button2->Text = L"Найти";
            this->button2->UseVisualStyleBackColor = true;
            this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
            // 
            // button3
            // 
            this->button3->Location = System::Drawing::Point(282, 300);
            this->button3->Name = L"button3";
            this->button3->Size = System::Drawing::Size(65, 20);
            this->button3->TabIndex = 7;
            this->button3->Text = L"Заменить";
            this->button3->UseVisualStyleBackColor = true;
            this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
            // 
            // button4
            // 
            this->button4->Location = System::Drawing::Point(367, 299);
            this->button4->Name = L"button4";
            this->button4->Size = System::Drawing::Size(65, 20);
            this->button4->TabIndex = 8;
            this->button4->Text = L"Удалить";
            this->button4->UseVisualStyleBackColor = true;
            this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Location = System::Drawing::Point(29, 251);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(32, 13);
            this->label1->TabIndex = 9;
            this->label1->Text = L"Имя:";
            // 
            // label2
            // 
            this->label2->AutoSize = true;
            this->label2->Location = System::Drawing::Point(29, 278);
            this->label2->Name = L"label2";
            this->label2->Size = System::Drawing::Size(55, 13);
            this->label2->TabIndex = 10;
            this->label2->Text = L"Телефон:";
            // 
            // label3
            // 
            this->label3->AutoSize = true;
            this->label3->Location = System::Drawing::Point(29, 304);
            this->label3->Name = L"label3";
            this->label3->Size = System::Drawing::Size(38, 13);
            this->label3->TabIndex = 11;
            this->label3->Text = L"E-mail:";
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(671, 384);
            this->Controls->Add(this->label3);
            this->Controls->Add(this->label2);
            this->Controls->Add(this->label1);
            this->Controls->Add(this->button4);
            this->Controls->Add(this->button3);
            this->Controls->Add(this->button2);
            this->Controls->Add(this->button1);
            this->Controls->Add(this->textBox4);
            this->Controls->Add(this->textBox3);
            this->Controls->Add(this->textBox2);
            this->Controls->Add(this->textBox1);
            this->Controls->Add(this->listView1);
            this->Name = L"Form1";
            this->Text = L"Form1";
            this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
            this->ResumeLayout(false);
            this->PerformLayout();
 
        }
в следующем сообщении остатки кода
0
IT_Exp
Эксперт
34794 / 4073 / 2104
Регистрация: 17.06.2006
Сообщений: 32,602
Блог
20.11.2015, 19:45
Ответы с готовыми решениями:

Ошибки в коде - идентификаторы GetUserNameEx, NameSamCompatible, counUserFNameBuffer не определены
Ошибки в 61 и 62 строках кода - идентификаторы GetUserNameEx, NameSamCompatible, counUserFNameBuffer не определены. Выполнялось это к 1...

Исправить ошибку "идентификаторы max и max_n не определены"
min = max = A, min_n = max_n = 0; У меня выдает ошибку что max и max_n не определены, как сделать?? #include &lt;iostream&gt; ...

Слайдер Dle (Почти сделал, Хелп)
Добрый день всем! Вот на сайте http://roshack.ru установлен слайдер, но при наведении мышки на картинку и нажатии на неё нечего не...

1
1 / 1 / 0
Регистрация: 06.01.2015
Сообщений: 13
20.11.2015, 19:45  [ТС]
C++
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#pragma endregion=
    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
        SqlCeEngine^ engine;
        engine =gcnew SqlCeEngine("Data Source='contacts.sdf';");
        if (!(File::Exists("contacts.sdf")))
        {
            engine->CreateDatabase();
            SqlCeConnection^ connection = gcnew SqlCeConnection(engine->LocalConnectionString);
            connection->Open();
            SqlCeCommand^ command = connection->CreateCommand();
            command->CommandText = "CREATE TABLE contacts (cid int IDENTITY(1,1), name nvarchar(50) NOT NULL, phone nvarchar(50),email nvarchar(50))";
            command->ExecuteScalar();
            connection->Close();
        }
        else
        {
            ShowDB();
        }
    }
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    SqlCeConnection^ conn = gcnew SqlCeConnection("Data Source ='contacts.sdf'");
    conn->Open();
    SqlCeCommand^ command = conn->CreateCommand();
    command->CommandText ="INSERT INTO contacts(name, phone,email) VALUES(?,?,?)";
    command->Parameters->Add("name", textBox1->Text);
    command->Parameters->Add("phone", textBox2->Text);
    command->Parameters->Add("email", textBox3->Text);
    command->ExecuteScalar();
    conn->Close();
    textBox1->Clear();
    textBox2->Clear();
    textBox3->Clear();
    ShowDB();
    textBox1->Focus();
}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
    SqlCeEngine^ engine = gcnew SqlCeEngine("Data Source='contacts.sdf';");
    SqlCeConnection^ connection = gcnew SqlCeConnection(engine->LocalConnectionString);
    connection->Open();
 
    SqlCeCommand^ command = connection->CreateCommand();
    command->CommandText = "SELECT * FROM contacts WHERE (name LIKE ?)";
    command->Parameters->Add("name","%" + textBox1->Text + "%");
    SqlCeDataReader^ dataReader = command->ExecuteReader();
    String^ st; // значение поля БД
    int itemIndex = 0;
    listView1->Items->Clear();
    while (dataReader->Read())
    {
        for (int i = 0; i < dataReader->FieldCount; i++)
        {
            st = dataReader->GetValue(i)->ToString();
            switch (i)
            {
            case 0: 
                listView1->Items->Add(st);
                break;
            case 1:
                listView1->Items[itemIndex]->SubItems->Add(st);
                break;
            case 2: 
                listView1->Items[itemIndex]->SubItems->Add(st);
                break;
            case 3: 
                listView1->Items[itemIndex]->SubItems->Add(st);
                break;
            };
        }
        itemIndex++;
    }
    connection->Close();
}
private: System::Void listView1_ItemSelectionChanged(System::Object^  sender, System::Windows::Forms::ListViewItemSelectionChangedEventArgs^  e) {
    if (e->IsSelected)
    {
        textBox4->Text = listView1->Items[e->ItemIndex]->Text;
    
        for (int i = 1;i < listView1->Items[e->ItemIndex]->SubItems->Count;i++)
        {
            switch (i)
            {
            case 1:
                textBox1->Text =
                    listView1->Items[e->ItemIndex]->SubItems[i]->Text;
                break;
            case 2:
                textBox2->Text =
                    listView1->Items[e->ItemIndex]->SubItems[i]->Text;
                break;
            case 3:
                textBox3->Text =
                    listView1->Items[e->ItemIndex]->SubItems[i]->Text;
                break;
            }
        }
    }
}
private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {
    if (listView1->SelectedItems->Count != 0)
    {
        SqlCeEngine^ engine = gcnew SqlCeEngine("Data Source='contacts.sdf';");
 
        SqlCeConnection^ connection = gcnew SqlCeConnection(engine->LocalConnectionString);
 
        connection->Open();
        SqlCeCommand^ command = connection->CreateCommand();
        command->CommandText = "DELETE FROM contacts WHERE (cid = ?)";
        command->Parameters->Add("cid", textBox4->Text);
 
        command->ExecuteScalar(); // выполнить команду
        ShowDB();
        textBox1->Clear();
        textBox2->Clear();
        textBox3->Clear();
        textBox4->Clear();
    }
}
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
    if (listView1->SelectedItems->Count != 0)
    {
        SqlCeEngine^ engine = gcnew SqlCeEngine("Data Source='contacts.sdf';");
        SqlCeConnection^ connection = gcnew SqlCeConnection(engine->LocalConnectionString);
        connection->Open();
        SqlCeCommand^ command = connection->CreateCommand();
        command->CommandText =
            "UPDATE contacts " +
            "SET name = ?, phone =?, email=? " +
            "WHERE cid = ?";
 
        command->Parameters->Add("name", textBox1->Text);
        command->Parameters->Add("phone", textBox2->Text);
        command->Parameters->Add("email", textBox3->Text);
        command->Parameters->Add("cid", textBox4->Text);
        command->ExecuteScalar(); // выполнить команду
        ShowDB();
        textBox1->Clear();
        textBox2->Clear();
        textBox3->Clear();
        textBox4->Clear();
    }
}
private: System::Void textBox3_TextChanged(System::Object^  sender, System::EventArgs^  e) {
    if ((textBox1->TextLength > 0) && ((textBox2->TextLength > 0) || (textBox3->TextLength > 0)))
    {
        button1->Enabled = true;
    }
    else
    {
        button1->Enabled = false;
    }
}
private: System::Void textBox2_TextChanged(System::Object^  sender, System::EventArgs^  e) {
    if ((textBox1->TextLength > 0) && ((textBox2->TextLength > 0) || (textBox3->TextLength > 0)))
    {
        button1->Enabled = true;
    }
    else
    {
        button1->Enabled = false;
    }
}
private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
    if ((textBox1->TextLength > 0) && ((textBox2->TextLength > 0) || (textBox3->TextLength > 0)))
    {
        button1->Enabled = true;
    }
    else
    {
        button1->Enabled = false;
    }
}
};
}
0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
BasicMan
Эксперт
29316 / 5623 / 2384
Регистрация: 17.02.2009
Сообщений: 30,364
Блог
20.11.2015, 19:45
Помогаю со студенческими работами здесь

Нарисовать ромб через цикл,почти сделал,не могу понять что делать дальше
#include &lt;iostream&gt; #include &lt;math.h&gt; #include &lt;conio.h&gt; using namespace std; int main() { int N,i; N=10; for...

Toshiba satellite 4хлетний почти не включается, некоторые кнопки не работают
Никогда траблов с ноутом не было. Внезапно перестал включаться: включение экрана, BIOS не успевает загрузится, виснет на первых строках и...

База данных, основанная на службах vs База данных SQL Server
Доброго времени суток. Делал я, значит, Data Access Layer для ASP.NET MVC проекта. Создал обычную библиотеку классов, моделей туда...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
2
Ответ Создать тему
Новые блоги и статьи
Как я обхитрил таблицу Word
Alexander-7 21.03.2026
Когда мигает курсор у внешнего края таблицы, и нам надо перейти на новую строку, а при нажатии Enter создается новый ряд таблицы с ячейками, то мы вместо нервных нажатий Энтеров мы пишем любые буквы. . .
Krabik - рыболовный бот для WoW 3.3.5a
AmbA 21.03.2026
без регистрации и смс. Это не торговля, приложение не содержит рекламы. Выполняет свою непосредственную задачу - автоматизацию рыбалки в WoW - и ничего более. Однако если админы будут против -. . .
Программный отбор значений справочника
Maks 21.03.2026
Установка программного отбора значений справочника "Сотрудники" из модуля формы документа. В качестве фильтра для отбора служит предопределенное значение перечислений. Процедура. . .
Переходник USB-CAN-GPIO
Eddy_Em 20.03.2026
Достаточно давно на работе возникла необходимость в переходнике CAN-USB с гальваноразвязкой, оный и был разработан. Однако, все меня терзала совесть, что аж 48-ногий МК используется так тупо: просто. . .
Оттенки серого
Argus19 18.03.2026
Оттенки серого Нашёл в интернете 3 прекрасных модуля: Модуль класса открытия диалога открытия/ сохранения файла на Win32 API; Модуль класса быстрого перекодирования цветного изображения в оттенки. . .
SDL3 для Desktop (MinGW): Рисуем цветные прямоугольники с помощью рисовальщика SDL3 на Си и C++
8Observer8 17.03.2026
Содержание блога Финальные проекты на Си и на C++: finish-rectangles-sdl3-c. zip finish-rectangles-sdl3-cpp. zip
Символические и жёсткие ссылки в Linux.
algri14 15.03.2026
Существует два типа ссылок — символические и жёсткие. Ссылка в Linux — это запись в каталоге, которая может указывать либо на inode «файла-ИСТОЧНИКА», тогда это будет «жёсткая ссылка» (hard link),. . .
[Owen Logic] Поддержание уровня воды в резервуаре количеством включённых насосов: моделирование и выбор регулятора
ФедосеевПавел 14.03.2026
Поддержание уровня воды в резервуаре количеством включённых насосов: моделирование и выбор регулятора ВВЕДЕНИЕ Выполняя задание на управление насосной группой заполнения резервуара,. . .
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2026, CyberForum.ru