So let me start by saying that I am a complete beginner when coding in C++ windows/forms program. I was able to get my SQL database connection up with my program. I've ran some simple tests and it looks like my program is able to do simple queries such as inserting values into a table and such. My real hope, now, is for me to have my program take what's in one of my textboxes (username textbox for this example) and put it into my SQL database (Polynomigra), table (logins), field (username). I have not a clue how the syntax goes for this query. I also have no idea why the data type "string" is not existent in C++ windows forms applications. Can someone help me out? And again, I mention to you all that I am a complete beginner at this--I'm teaching myself how to do this.

Thanks and here's the code.

    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                MySqlConnection^ con = gcnew MySqlConnection("Network Address=localhost;" "User Name='root';" "Password='password';" "database=Polynomigra");

                con->Open();

                string username = usernameText.Text;

                MySqlCommand^ cmdExecute = gcnew MySqlCommand("INSERT INTO logins VALUES ('1','testuser','testpassword')", con);
                MySqlDataReader^ reader = cmdExecute->ExecuteReader();

                con->Close();
             }

Recommended Answers

All 2 Replies

I also have no idea why the data type "string" is not existent in C++ windows forms applications.

Windows Forms is not c++, its CLI/C++ which is a slightly different language. CLI/C++ does not support c++ code or classes like std::string, std::vector, etc. The VC++ 2010 compiler has some of the classes in the include/cliext and is in cliext namespace, not std namespace. If you are not familiar with cli/c++ then you should read one of the many tutorials and walkthroughs that you can easily find with google. Yes I know its difficult to figure out where everything is because you can' just include <string> header file and expect to use its String class.

As for your specific problem, I don't know either because I have not used CLI/C++ enough, but I'm sure that is a common problem and your should be able to google for the answer.

Your code is calling ExecuteReader. That's not what you're trying to do ("reader").

You need ExecuteNonQuery()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.