hellow!!
i mworking in c++ managed on vsual studio c++ 2010 express edition but when i get the text from a text zone and use it in an other traitement it's gve me tis error:
de 'System::String ^' en 'System::String ^[256]'
nd there is my code:

private: System::Void BGENER_Click(System::Object^  sender, System::EventArgs^  e) {
char  szSql12[256];
String^ val;
String^ val2;
val=TIDBMK->Text;
val2=INOMBAMK->Text;
szSql12="insert into BANK(CODE_BANK,NOM_BANK) values ('"+val+"','"val2"')";
rc = SQLAllocStmt(hDbc,&hStmt);
rc=SQLExecDirectA(hStmt,szSql12,SQL_NTS);


}

Recommended Answers

All 5 Replies

Ton problème est que lorsque tu fais l'addition de plusieurs chaines de charactères, ses chaines sont converties en "String^" pour être additionner. Une fois additionné, tu as un String et non une chaines de charactère (char[] ou char*), et ils ne sont pas compatible implicitement. Donc, pour régler le problème, déclare la variable szSql12 de type "String^" et lorsque tu doit appeler "SQLExecDirectA()", passe comme paramètre "szSQL12.c_str()" à la place de juste "szSQL12".

i dont think so bcause i still have d sam error whch:

error C2440: 'cast de type' : impossible de convertir de 'System::String ^' en 'SQLCHAR *'

Ton problème est que lorsque tu fais l'addition de plusieurs chaines de charactères, ses chaines sont converties en "String^" pour être additionner. Une fois additionné, tu as un String et non une chaines de charactère (char[] ou char*), et ils ne sont pas compatible implicitement. Donc, pour régler le problème, déclare la variable szSql12 de type "String^" et lorsque tu doit appeler "SQLExecDirectA()", passe comme paramètre "szSQL12.c_str()" à la place de juste "szSQL12".

(For the English speakers that can't comprehend a lick of French)

Your problem is that when you combine several character arrays together they are converted into a String^. Once combined, you have a String, and not a character array (char[] or char*), and they are not implicitly compatible. Therefore, to correct the problem, declare szSql12 as a String^ and when you call "SQLExecDirectA()", pass the argument as "szSQL12.c_str()" instead of as only "szSQL12".

@mike:
I don't know .NET so unfortunately I can't help the OP. However, I think you may be getting the .NET String class confused with C++'s std::string.

commented: For the translation +4

Have a look at something like this:
http://msdn.microsoft.com/en-us/library/1b4az623.aspx

This is one of those unfortunate cases where the unmanaged and the managed data types cannot be interchanged, you need to marshal the string.

10ks that's help a lot 10k's :kiss:

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.