6 Replies - 651 Views - Last Post: 27 April 2013 - 02:37 AM Rate Topic: -----

#1 codejunky  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 18-April 13

C++ mysql help

Posted 18 April 2013 - 10:28 AM

I created a registration form and when i test if my mysql insert query is successful nothing happens... also notice the query isn't going through. if i take out my if() statements

 if(rowsAffected >0)
			 {
				 MessageBox::Show("Registration Successful!");
				 login^ f5 =gcnew login();
				 f5->ShowDialog();
			 }
			else
			 {
				 MessageBox::Show("Registration Failed!");
				 Application::Exit();
			 }	





and change it to ExecuteReader();

MySqlDataReader^ myReader; myReader=cmdDataBase->ExecuteReader(); 


the query goes through fine...

Not sure what i'm doing wrong, it seems fine...
how do i submit the insert query and check to see if it was successfully submitted?? ExecuteNonQuery(); doesn't work and not sure why???


private: System::Void registration_button_Click(System::Object^  sender, System::EventArgs^  e) {

			  String^ constring=L"datasource=applicationdata.db.104xxxxx.hostedresource.com;port=3306;username=applicationdatas;password=xxxxxx";
			 MySqlConnection^ conDataBase=gcnew MySqlConnection(constring);
			 MySqlCommand^ cmdDataBase=gcnew MySqlCommand("insert into applicationdatas.app_users (fname, email, password, address, country, state, city, postal_code, phone) VALUES ('"+this->ufullname_txt->Text+"', '"+this->uemail_txt->Text+"', '"+this->upassword_txt->Text+"', '"+this->uaddress_txt->Text+"', '"+this->country_comboBox->Text+"', '"+this->state_comboBox->Text+"', '"+this->city_comboBox->Text+"', '"+this->zipcode_txt->Text+"', '"+this->phone_txt->Text+"') ;",conDataBase);
			 //MySqlDataReader^ myReader;

			 try{
			 conDataBase->Open();
			 //myReader=cmdDataBase->ExecuteReader();
			 	
			 int rowsAffected = cmdDataBase->ExecuteNonQuery();
			 
			 if(rowsAffected >0)
			 {
				 MessageBox::Show("Registration Successful!");
				 login^ f5 =gcnew login();
				 f5->ShowDialog();
			 }
			else
			 {
				 MessageBox::Show("Registration Failed!");
				 Application::Exit();
			 }	

			 conDataBase->Close();
			 

			 }catch(Exception^ex){
			 
			 MessageBox::Show(ex->Message);
			 
			 
			 }

		 }



From what i understand the ExecuteNonQuery(); should give affected rows but for some reason it's not working...

Is This A Good Question/Topic? 0
  • +

Replies To: C++ mysql help

#2 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 656
  • View blog
  • Posts: 2,247
  • Joined: 31-December 10

Re: C++ mysql help

Posted 18 April 2013 - 01:49 PM

What db library is this that you're using?
Was This Post Helpful? 0
  • +
  • -

#3 codejunky  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 18-April 13

Re: C++ mysql help

Posted 18 April 2013 - 03:44 PM

View Postvividexstance, on 18 April 2013 - 01:49 PM, said:

What db library is this that you're using?



MySQL Connector Net 6.6.5
Was This Post Helpful? 0
  • +
  • -

#4 codejunky  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 18-April 13

Re: C++ mysql help

Posted 18 April 2013 - 04:11 PM

View Postcodejunky, on 18 April 2013 - 03:44 PM, said:

View Postvividexstance, on 18 April 2013 - 01:49 PM, said:

What db library is this that you're using?



MySQL Connector Net 6.6.5


The code is working 100% fine aside from the if statement in my try catch block.
I must be having some confusion as to how the ExecuteReader(); and ExecuteNonQuery(); are used.
My understanding is that ExecuteNonQuery(); should give affected rows of insert, select, and delete query.
ExecuteReader(); "Sends the CommandText to the Connection and builds a SqlDataReader."

When I use ExecuteNonQuery(); nothing happens... the query doesn't get sent and the check for affected rows in my if statement does nothing either.

When I use ExecuteReader(); the query goes through fine, but I have no way to check it... that I know of.
Was This Post Helpful? 0
  • +
  • -

#5 codejunky  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 18-April 13

Re: C++ mysql help

Posted 18 April 2013 - 04:56 PM

Got it figured out...



View Postcodejunky, on 18 April 2013 - 04:11 PM, said:

View Postcodejunky, on 18 April 2013 - 03:44 PM, said:

View Postvividexstance, on 18 April 2013 - 01:49 PM, said:

What db library is this that you're using?



MySQL Connector Net 6.6.5


The code is working 100% fine aside from the if statement in my try catch block.
I must be having some confusion as to how the ExecuteReader(); and ExecuteNonQuery(); are used.
My understanding is that ExecuteNonQuery(); should give affected rows of insert, select, and delete query.
ExecuteReader(); "Sends the CommandText to the Connection and builds a SqlDataReader."

When I use ExecuteNonQuery(); nothing happens... the query doesn't get sent and the check for affected rows in my if statement does nothing either.

When I use ExecuteReader(); the query goes through fine, but I have no way to check it... that I know of.

Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3552
  • View blog
  • Posts: 11,009
  • Joined: 05-May 12

Re: C++ mysql help

Posted 18 April 2013 - 08:01 PM

Congratulations on figuring it out.

Out of curiosity, why are you torturing yourself using C++/CLI? Writing that code in C# would have been easier and less verbose.
Was This Post Helpful? 0
  • +
  • -

#7 codejunky  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 18-April 13

Re: C++ mysql help

Posted 27 April 2013 - 02:37 AM

Yeah good plan. =)

View PostSkydiver, on 18 April 2013 - 08:01 PM, said:

Congratulations on figuring it out.

Out of curiosity, why are you torturing yourself using C++/CLI? Writing that code in C# would have been easier and less verbose.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1