WEB开发网
开发学院软件开发VC AppBuilder中进行直接ODBC API数据库调用访问的基... 阅读

AppBuilder中进行直接ODBC API数据库调用访问的基本方法!

 2008-09-25 19:27:00 来源:WEB开发网   
核心提示: 八、写数据库1、普通方法:CString strSQL="INSERT INTO TABLE (FILE1,FILE2,FILE3) VALUES (value1,value2,value3)"long ExecuteSQL(SQLHDBC hdbc,CString s

八、写数据库

1、普通方法:

  CString strSQL="INSERT INTO TABLE (FILE1,FILE2,FILE3) VALUES (value1,value2,value3)"
  long ExecuteSQL(SQLHDBC hdbc,CString strSQL)
  {
  SQLRETURN ReturnCode;
  SQLHSTMT m_hstmt;
  BOOL bReturn = FALSE;
  long nRowCount = 0;
  if (SQL_SUCCESS == (ReturnCode = ::SQLAllocHandle(SQL_HANDLE_STMT,hdbc,&m_hstmt)))
  {
  if (SQL_SUCCESS == (ReturnCode = ::SQLExecDirect(m_hstmt, (UCHAR*)((LPCTSTR)strSQL),SQL_NTS)))
  {
  bReturn = TRUE;
  ::SQLRowCount(m_hstmt,&nRowCount);
  }
  }
  ReturnCode = ::SQLFreeHandle(SQL_HANDLE_STMT,m_hstmt);
  // if (!bReturn) nRowCount = 0;
  return nRowCount;
  }

注意,要把字段赋为空,字符串、日期应是NULL,可以用下面的函数修改:

  CString VerifySQLStr(CString strSQL)
  {
  int nLength = strSQL.GetLength();
  int n1 = 0;//check ´´;
  int n2 = 0;
  int m1 = 0;//check ##;
  int m2 = 0;
  for (int i = 0; i< nLength;i++)
  {
  if (strSQL[i] == 39)
  {
  n2 = i;
  if (n2-n1 == 1)
  {
  strSQL.Delete(n1,2);
  strSQL.Insert(n1,"NULL");
  nLength +=2;
  n1 = n2;
  }
  else
  {
  n1 = n2;
  }
  }
  if (strSQL[i] == ´#´)
  {
  m2 = i;
  if (m2-m1 == 1)
  {
  strSQL.Delete(m1,2);
  strSQL.Insert(m1,"NULL");
  nLength +=2;
  m1 = m2;
  }
  else
  {
  m1 = m2;
  }
  }
  }
  return strSQL;
  }

上一页  4 5 6 7 8 9 10  下一页

Tags:AppBuilder 进行 直接

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接