Q:

Appending an numeric value at the and of String

i am trying to insert multiple insert in table. For that i have created an int column table and inserting using for loop function but i am not able to write proper code which i want to do.
i Need some thing like that
for(i=0;i<1800;i++)
{

    retcode =  SQLPrepare(hstmt,(SQLCHAR *)"insert into dbo.vivtest values(i)",SQL_NTS);
    if (retcode != SQL_SUCCESS)
        {
            printf("Error in SQLPrepare - insert\n");
            odbc_Error(henv,hdbc,hstmt);
            getch();
        }
    else
        printf("Successfull execution of  %d th  Prepare\n",i);

It's giving me error every time.

A:

The following is a useful link about SQLPrepare() and how to bind parameters. Binding parameters is a safe way of inserting variable contents into your SQL strings and also a prepared statement made in this way is an efficient way of executing a statement multiple times.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms716365(v=vs.85).aspx
It gives an example of binding parameters to an SQL query. The give the following example:
SQLPrepare(hstmt, "UPDATE Parts SET Price = ? WHERE PartID = ?", SQL_NTS);

In the SQL string you can see a few ? (question marks). These are like placeholders in the SQL string which you can then "bind parameters to" (i.e., substitute in a variable contents in place of).
To continue the MSDN example...
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_REAL, 7, 0,
                  &Price, 0, &PriceInd);
SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 10, 0,
                  &PartID, 0, &PartIDInd);

The first statement replaces the first question mark with a floating point value from the variable Price and the second bind replaces the second question mark with an integer from the PartID variable.
Your prepare statement should probably looks something like...
SQLINTEGER    iInd;
SQLUINTEGER   i;
...
...
retcode =  SQLPrepare(hstmt,(SQLCHAR *)"insert into dbo.vivtest values(?)",SQL_NTS);
...
...
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 10, 0,
              &i, 0, &iInd);

A:

You should use either SQL Parameters, or sprintf().
Preferably the former.

