Click to See Complete Forum and Search --> : Building a windows application


waelr
December 8th, 2005, 04:59 AM
hey guys
im new to building c++ windows applications.net
to insert data into a table im using the followin code:

sqlConnection1->Open();
sqlCommand1->CommandText = "insert into countries (namecountry) values ('" textBox1->Text "')";
sqlCommand1->ExecuteNonQuery();
MessageBox::Show("Done");
sqlConnection1->Close();

looks like am getting an error with the "textBox1.Text"
when replacing it with :
sqlCommand1->CommandText = "insert into countries (namecountry) values ('France')"; --- it works fine
thank u

Tischnoetentoet
December 8th, 2005, 05:21 AM
You are using the textBox1 as a pointer. Can you show us the declaration?

waelr
December 8th, 2005, 09:03 AM
I just put a TextBox from the 'Windows Form' and the following code was automatically generated:

private: System::Windows::Forms::TextBox * textBox1;

Mitsukai
December 8th, 2005, 12:13 PM
i dont think the .ne syntax is right shouldnt it be someting like & text & ?
dunno .net but would seem logical to me

Paul McKenzie
December 8th, 2005, 12:50 PM
I just put a TextBox from the 'Windows Form' and the following code was automatically generated:

private: System::Windows::Forms::TextBox * textBox1;Wrong forum.

You want the Managed C++ forum.

Regards,

Paul McKenzie

Ejaz
December 8th, 2005, 01:02 PM
[ Moved Thread ]

NoHero
December 8th, 2005, 01:19 PM
sqlCommand1->CommandText = String::Format(S"insert into countries (namecountry) values ('{0}')", textBox1->get_Text());

You forgot the S praefix - which tells the compiler to treat your string literal as a System::String*. And well, the SQL statements look clearer when assembled with String::Format().