Can you please give me an example for c++. which works on Visual studio 2019.
I tried this
char test_name[50];
char SQLQueryViewMARKS_12A[] = "SELECT *FROM Marks_12A WHERE Test_Name = ";
cin>>test_name;
strcat_s(SQLQueryViewMARKS_12A,sizeof(SQLQueryViewMARKS_12A),"'/0 ");
strcat_s(SQLQueryViewMARKS_12A,sizeof(SQLQueryViewMARKS_12A),test_name);
strcat_s(SQLQueryViewMARKS_12A,sizeof(SQLQueryViewMARKS_12A), "'/0");
The expected result was :
If user entered UT
The query must get concatenate to
char SQLQueryViewMARKS_12A[] = "SELECT *FROM Marks_12A WHERE Test_Name = ' UT ' ";
Your code is almost right. The only thing that is missing is the space for the additional string that you would like concatenated to the original:
char SQLQueryViewMARKS_12A[128] = "SELECT *FROM Marks_12A WHERE Test_Name = ";
// ^^^
// Give your string more space to ensure that additional characters have place to fit
//
strcat_s(SQLQueryViewMARKS_12A,sizeof(SQLQueryViewMARKS_12A),"'/0 ");
Note that although strcat_s works fine in C++, std::string from the Standard C++ library gives you a much more powerful alternative:
std::string SQLQueryViewMARKS_12A = "SELECT *FROM Marks_12A WHERE Test_Name = ";
SQLQueryViewMARKS_12A += "'/0 ";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With