#c #mysql #visual-studio-2019 #mysql-connector #mysql-connector-c
Вопрос:
Я создал приложение Windows form на C и хочу привязать его к базе данных. Тем не менее, он продолжает выдавать мне ошибку, которую я не могу решить. Он выделяет мою conn
переменную, которая имеет тип MYSQL*
, и просто выдает мне эту ошибку: this declaration has no storage class or type specifier
. У меня все библиотеки связаны и включены, поэтому я не понимаю, в чем проблема.
Код:
#pragma once
#include <iostream>
#include <mysql.h>
MYSQL* conn;
MYSQL_ROW row;
MYSQL_RES* res;
conn = mysql_init(0);
conn = mysql_real_connect(conn, my host here, my username, my password, my db name, port, NULL, 0);
namespace MSSLogin {
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 Login_Panel : public System::Windows::Forms::Form
{
public:
Login_Panel(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
~Login_Panel()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
protected:
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::PictureBox^ pictureBox1;
private: System::Windows::Forms::Label^ label3;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Login_Panel::typeid));
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->button1 = (gcnew System::Windows::Forms::Button());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->label3 = (gcnew System::Windows::Forms::Label());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->Location = System::Drawing::Point(71, 25);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(90, 18);
this->label1->TabIndex = 0;
this->label1->Text = L"Username:";
this->label1->Click = gcnew System::EventHandler(this, amp;Login_Panel::label1_Click);
//
// label2
//
this->label2->AutoSize = true;
this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label2->Location = System::Drawing::Point(71, 56);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(88, 18);
this->label2->TabIndex = 1;
this->label2->Text = L"Password:";
this->label2->Click = gcnew System::EventHandler(this, amp;Login_Panel::label2_Click);
//
// button1
//
this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->button1->Location = System::Drawing::Point(118, 95);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(196, 32);
this->button1->TabIndex = 2;
this->button1->Text = L"Login";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click = gcnew System::EventHandler(this, amp;Login_Panel::button1_Click);
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(167, 23);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(192, 20);
this->textBox1->TabIndex = 3;
this->textBox1->TextChanged = gcnew System::EventHandler(this, amp;Login_Panel::textBox1_TextChanged);
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(167, 56);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(192, 20);
this->textBox2->TabIndex = 4;
this->textBox2->TextChanged = gcnew System::EventHandler(this, amp;Login_Panel::textBox2_TextChanged);
//
// pictureBox1
//
this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"pictureBox1.Image")));
this->pictureBox1->Location = System::Drawing::Point(364, 146);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(60, 55);
this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
this->pictureBox1->TabIndex = 5;
this->pictureBox1->TabStop = false;
this->pictureBox1->Click = gcnew System::EventHandler(this, amp;Login_Panel::pictureBox1_Click);
//
// label3
//
this->label3->AutoSize = true;
this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label3->Location = System::Drawing::Point(12, 183);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(185, 18);
this->label3->TabIndex = 6;
this->label3->Text = L"@misrsoftwaresystems";
this->label3->Click = gcnew System::EventHandler(this, amp;Login_Panel::label3_Click);
//
// Login_Panel
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(436, 213);
this->Controls->Add(this->label3);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->label1);
this->Controls->Add(this->label2);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
this->HelpButton = true;
this->Icon = (cli::safe_cast<System::Drawing::Icon^>(resources->GetObject(L"$this.Icon")));
this->MaximizeBox = false;
this->MinimizeBox = false;
this->Name = L"Login_Panel";
this->Text = L"Login";
this->Load = gcnew System::EventHandler(this, amp;Login_Panel::Login_Panel_Load);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void groupBox1_Enter(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void textBox2_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label2_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label3_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void Login_Panel_Load(System::Object^ sender, System::EventArgs^ e) {
}
};
}
Я пытался постоянно перемещать этот блок кода в пространство имен и класс и из него, надеясь, что это возымеет эффект, но, очевидно, нет.
Журналы ошибок:
Warning C4829 Possibly incorrect parameters to function main. Consider 'int main(Platform::Array<Platform::String^>^ argv)' MSS_Login D:MSSMSS_SystemMSS_LoginLogin_Panel.cpp 7
Error C2664 'MYSQL *mysql_real_connect(MYSQL *,const char *,const char *,const char *,const char *,unsigned int,const char *,unsigned long)': cannot convert argument 1 from 'int' to 'MYSQL *' MSS_Login D:MSSMSS_SystemMSS_LoginLogin_Panel.h 10
Error C4430 missing type specifier - int assumed. Note: C does not support default-int MSS_Login D:MSSMSS_SystemMSS_LoginLogin_Panel.h 10
Error C2374 'conn': redefinition; multiple initialization MSS_Login D:MSSMSS_SystemMSS_LoginLogin_Panel.h 10
Error C2440 'initializing': cannot convert from 'MYSQL *' to 'int' MSS_Login D:MSSMSS_SystemMSS_LoginLogin_Panel.h 8
Error C4430 missing type specifier - int assumed. Note: C does not support default-int MSS_Login D:MSSMSS_SystemMSS_LoginLogin_Panel.h 8
Error (active) E0077 this declaration has no storage class or type specifier MSS_Login D:MSSMSS_SystemMSS_LoginLogin_Panel.h 10
Error (active) E0077 this declaration has no storage class or type specifier MSS_Login D:MSSMSS_SystemMSS_LoginLogin_Panel.h 8
Скриншоты моих связанных libs
и includes
:
C/C > General > Additional Include Directories
Первое изображение каталогов включения
Linker > General > Additional Library Directories
Второе изображение библиотечных каталогов
Linker > Input > Additional Dependencies
Третье изображение дополнительных зависимостей
Ответ №1:
Я получил ответ, он должен быть в пределах функции. Я неправильно понял ошибку из-за чего-то другого. Моя вина
Комментарии:
1. Пожалуйста, укажите дополнительную информацию в своем ответе. Как это написано в настоящее время, трудно понять ваше решение.