我正在尝试将以下查询插入到SQL Server中。我对C ++有点陌生。如果有人可以为我提供有用的资源,或者给我提供解决方法。我将不胜感激。
Insert into SInvoice Values('SIV-2',0,1,1,5.000000,0.000000,'04/01/2019 08:49:46',8.000000,40.000000,'',0,1,1,1,1,'04/01/2019 08:49:46','',1.000000,1,0,'','b',0.000000,5,0.000000,40.000000,'Nos',1.000000,'','','','','','','','','','','','','','','','','','','','','',0,3,'SIV-',1,1,1,1,1,1,3.330000);
使用c ++。我尝试从中获取数据,并且成功了。我真的没有找到关于插入的信息。
这是获取数据的c ++代码。哪个有用。
// ConsoleApplication4.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "pch.h"
#include <iostream>
#include <Windows.h>
#include <sqlext.h>
#include <sqltypes.h>
#include <sql.h>
using namespace std;
void showSQLError(unsigned int handleType, const SQLHANDLE& handle) {
SQLCHAR SQLState[1024];
SQLCHAR message[1024];
if (SQL_SUCCESS == SQLGetDiagRec(handleType, handle, 1, SQLState, NULL, message, 1024, NULL)) {
cout << "SQL driver message: " << message << "\nSQL state: " << SQLState << "." << endl;
}
}
int main()
{
SQLHANDLE SQLEnvHandle = NULL;
SQLHANDLE SQLConnectionHandle = NULL;
SQLHANDLE SQLStatmentHandle = NULL;
SQLRETURN retCode = 0;
char SQLQuery[] = "select * from sec";
do {
if (SQL_SUCCESS != SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &SQLEnvHandle))
break;
if (SQL_SUCCESS != SQLSetEnvAttr(SQLEnvHandle, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0))
break;
if (SQL_SUCCESS != SQLAllocHandle(SQL_HANDLE_DBC, SQLEnvHandle, &SQLConnectionHandle))
break;
SQLCHAR retConString[1024];
switch (SQLDriverConnect(SQLConnectionHandle, NULL, (SQLCHAR*)"DRIVER={SQL SERVER}; SERVER=OMAR; DATABASE=AccountsC20; UID=ofamo; PWD=mypass", SQL_NTS, retConString, 1024, NULL, SQL_DRIVER_NOPROMPT)) {
case SQL_SUCCESS:
break;
case SQL_ROW_SUCCESS_WITH_INFO:
break;
case SQL_NO_DATA_FOUND:
showSQLError(SQL_HANDLE_DBC, SQLConnectionHandle);
retCode = -1;
break;
case SQL_INVALID_HANDLE:
showSQLError(SQL_HANDLE_DBC, SQLConnectionHandle);
retCode = -1;
break;
case SQL_ERROR:
showSQLError(SQL_HANDLE_DBC, SQLConnectionHandle);
retCode = -1;
break;
default:
break;
}
if (retCode == -1)
break;
if (SQL_SUCCESS != SQLAllocHandle(SQL_HANDLE_STMT, SQLConnectionHandle, &SQLStatmentHandle))
break;
if (SQL_SUCCESS != SQLExecDirect(SQLStatmentHandle, (SQLCHAR*)SQLQuery, SQL_NTS)){
showSQLError(SQL_HANDLE_STMT, SQLStatmentHandle);
break;
}
else {
char name[256];
int Id;
while (SQLFetch(SQLStatmentHandle) == SQL_SUCCESS) {
SQLGetData(SQLStatmentHandle, 1, SQL_C_DEFAULT, &name, size(name), NULL);
SQLInse
cout << name << endl;
}
}
}
while (FALSE);
SQLFreeHandle(SQL_HANDLE_STMT, SQLStatmentHandle);
SQLDisconnect(SQLConnectionHandle);
SQLFreeHandle(SQL_HANDLE_DBC, SQLConnectionHandle);
SQLFreeHandle(SQL_HANDLE_ENV, SQLEnvHandle);
return 0;
}
如何使其执行上面的以下查询。谢谢。