Click here to Skip to main content
15,902,299 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to copy data within first text file to second text file (use CStdioFile) Pin
Christian Graus28-Oct-02 18:36
protectorChristian Graus28-Oct-02 18:36 
GeneralRe: How to copy data within first text file to second text file (use CStdioFile) Pin
ooosawaddee328-Oct-02 19:02
ooosawaddee328-Oct-02 19:02 
GeneralRe: How to copy data within first text file to second text file (use CStdioFile) Pin
Christian Graus28-Oct-02 19:20
protectorChristian Graus28-Oct-02 19:20 
GeneralRe: How to copy data within first text file to second text file (use CStdioFile) Pin
Joaquín M López Muñoz28-Oct-02 20:31
Joaquín M López Muñoz28-Oct-02 20:31 
GeneralCFormView and CTabCtrl :: MFC Pin
valikac28-Oct-02 18:06
valikac28-Oct-02 18:06 
GeneralRe: CFormView and CTabCtrl :: MFC Pin
super29-Oct-02 1:55
professionalsuper29-Oct-02 1:55 
GeneralRe: CFormView and CTabCtrl :: MFC Pin
valikac29-Oct-02 4:31
valikac29-Oct-02 4:31 
Generalvb program rune fine but the same gives error in VC++ Pin
Anonymous28-Oct-02 18:07
Anonymous28-Oct-02 18:07 
my vb program is as follows
this works fine.

Option Explicit

#If Win32 Then

Private Declare Function SQLAllocEnv Lib "odbc32.dll" _
(phenv As Long) As Integer
Private Declare Function SQLAllocConnect Lib "odbc32.dll" _
(ByVal henv As Long, phdbc As Long) As Integer
Private Declare Function SQLConnect Lib "odbc32.dll" ( _
ByVal hdbc As Long, ByVal szDSN As String, _
ByVal cbDSN As Integer, ByVal szUID As String, _
ByVal cbUID As Integer, ByVal szAuthStr As String, _
ByVal cbAuthStr As Integer) As Integer
Private Declare Function SQLFreeEnv Lib "odbc32.dll" _
(ByVal henv As Long) As Integer
Private Declare Function SQLFreeConnect Lib "odbc32.dll" _
(ByVal hdbc As Long) As Integer
Private Declare Function SQLError Lib "odbc32.dll" ( _
ByVal henv As Long, ByVal hdbc As Long, ByVal hstmt As Long, _
ByVal szSqlState As String, pfNativeError As Long, _
ByVal szErrorMsg As String, ByVal cbErrorMsgMax As Integer, _
pcbErrorMsg As Integer) As Integer
#ElseIf Win16 Then
Private Declare Function SQLAllocEnv Lib "odbc.dll" _
(phenv As Long) As Integer
Private Declare Function SQLAllocConnect Lib "odbc.dll" _
(ByVal henv As Long, phdbc As Long) As Integer
Private Declare Function SQLConnect Lib "odbc.dll" ( _
ByVal hdbc As Long, ByVal szDSN As String, _
ByVal cbDSN As Integer, ByVal szUID As String, _
ByVal cbUID As Integer, ByVal szAuthStr As String, _
ByVal cbAuthStr As Integer) As Integer
Private Declare Function SQLFreeEnv Lib "odbc.dll" _
(ByVal henv As Long) As Integer
Private Declare Function SQLFreeConnect Lib "odbc.dll" _
(ByVal hdbc As Long) As Integer
Private Declare Function SQLError Lib "odbc.dll" ( _
ByVal henv As Long, ByVal hdbc As Long, _
ByVal hstmt As Long, ByVal szSqlState As String, _
pfNativeError As Long, ByVal szErrorMsg As String, _
ByVal cbErrorMsgMax As Integer, pcbErrorMsg As Integer) _
As Integer
#End If

Private Const SQL_SUCCESS As Long = 0
Private Const SQL_SUCCESS_WITH_INFO As Long = 1

Private Function IsValidODBCLogin(ByVal sDSN As String, _
ByVal sUID As String, ByVal sPWD As String) As Boolean
Dim henv As Long 'Environment Handle
Dim hdbc As Long 'Connection Handle
Dim iResult As Integer

'Obtain Environment Handle
iResult = SQLAllocEnv(henv)
If iResult <> SQL_SUCCESS Then
IsValidODBCLogin = False
Exit Function
End If

'Obtain Connection Handle
iResult = SQLAllocConnect(henv, hdbc)
If iResult <> SQL_SUCCESS Then
IsValidODBCLogin = False
iResult = SQLFreeEnv(henv)
Exit Function
End If

'Test Connect Parameters
iResult = SQLConnect(hdbc, sDSN, Len(sDSN), sUID, Len(sUID), _
sPWD, Len(sPWD))
If iResult <> SQL_SUCCESS Then
If iResult = SQL_SUCCESS_WITH_INFO Then
'The Connection has been successful, but SQLState Information
'has been returned
'Obtain all the SQLState Information
If Check1.Value Then ShowSQLErrorInfo hdbc, vbInformation
IsValidODBCLogin = True
Else
'Obtain all the Error Information
If Check1.Value Then ShowSQLErrorInfo hdbc, vbExclamation
IsValidODBCLogin = False
End If
Else
IsValidODBCLogin = True
End If

'Free Connection Handle and Environment Handle
iResult = SQLFreeConnect(hdbc)
iResult = SQLFreeEnv(henv)

End Function

Private Sub Form_Load()

Text1.Text = "DSN"
Text2.Text = "User ID"
Text3.Text = ""
Text3.PasswordChar = "*"
Command1.Caption = "Test Connect"
Check1.Caption = "Return Errors and Warnings"

End Sub

Private Sub Command1_Click()
Dim sServer As String, sLogin As String, sPassword As String

sServer = Text1.Text
sLogin = Text2.Text
sPassword = Text3.Text

If IsValidODBCLogin(sServer, sLogin, sPassword) = True Then
MsgBox "Connection Successful", vbInformation, "ODBC Logon"
Else
MsgBox "Connection Failed", vbExclamation, "ODBC Logon"
End If

End Sub

Private Sub ShowSQLErrorInfo(hdbc As Long, iMSGIcon As Integer)
Dim iResult As Integer
Dim hstmt As Long
Dim sBuffer1 As String * 16, sBuffer2 As String * 255
Dim lNative As Long, iOutlen As Integer

sBuffer1 = String$(16, 0)
sBuffer2 = String$(256, 0)

' Do 'Cycle though all the Errors
iResult = SQLError(0, hdbc, hstmt, sBuffer1, lNative, sBuffer2, _
256, iOutlen)
If iResult = SQL_SUCCESS Then
If iOutlen = 0 Then
MsgBox "Error -- No error information available", _
iMSGIcon, "ODBC Logon"
Else
MsgBox Left$(sBuffer2, iOutlen), iMSGIcon, "ODBC Logon"
End If
End If
' Loop Until iResult <> SQL_SUCCESS

End Sub

where as my VC ++ program is
this program doesn't work

void main()
{
SQLHENV m_SQLEnvironment;
SQLHDBC m_SQLConnection;
SQLRETURN iReturn;


// Obtain Environment Handle

iReturn = SQLAllocEnv(&m_SQLEnvironment);

if (iReturn != SQL_SUCCESS)
printf("Error in Allocating Environment");

// Obtain Connection Handle
iReturn = SQLAllocConnect(m_SQLEnvironment,&m_SQLConnection);

if (iReturn != SQL_SUCCESS)
{
printf("Error");
iReturn = SQLFreeEnv(m_SQLEnvironment);
}


//Test Connect Parameters

iReturn = SQLConnect(m_SQLConnection,(SQLCHAR*)"OraTest",SQL_NTS,(SQLCHAR *)"scott",SQL_NTS,(SQLCHAR *)"tiger",SQL_NTS);

if (iReturn != SQL_SUCCESS)
{
if (iReturn == SQL_SUCCESS_WITH_INFO)
{
// 'The Connection has been successful, but SQLState Information
// 'has been returned
// 'Obtain all the SQLState Information
// If Check1.Value Then ShowSQLErrorInfo hdbc, vbInformation
// IsValidODBCLogin = True
printf("Connected");
}
else
{
// 'Obtain all the Error Information
// If Check1.Value Then ShowSQLErrorInfo hdbc, vbExclamation
// IsValidODBCLogin = False
printf("Failed Connecting");
}
}
else
{
//IsValidODBCLogin = True
printf("Connected");
}

//'Free Connection Handle and Environment Handle
iReturn = SQLFreeConnect(m_SQLConnection);
iReturn = SQLFreeEnv(m_SQLEnvironment);
}

can anyone figure out the problem.
its urgent Confused | :confused:
GeneralRe: vb program rune fine but the same gives error in VC++ Pin
Anonymous29-Oct-02 0:52
Anonymous29-Oct-02 0:52 
GeneralRe: vb program rune fine but the same gives error in VC++ Pin
Anonymous29-Oct-02 18:36
Anonymous29-Oct-02 18:36 
GeneralRe: vb program rune fine but the same gives error in VC++ Pin
Rickard Andersson2029-Oct-02 2:16
Rickard Andersson2029-Oct-02 2:16 
GeneralRe: vb program rune fine but the same gives error in VC++ Pin
Anonymous29-Oct-02 18:46
Anonymous29-Oct-02 18:46 
Generalcant find WM_SETFOCUS for .... Pin
devvvy28-Oct-02 17:30
devvvy28-Oct-02 17:30 
GeneralRe: cant find WM_SETFOCUS for .... Pin
Shog928-Oct-02 18:29
sitebuilderShog928-Oct-02 18:29 
GeneralThanks, but... Pin
devvvy28-Oct-02 19:18
devvvy28-Oct-02 19:18 
GeneralRe: Thanks, but... Pin
Shog928-Oct-02 19:21
sitebuilderShog928-Oct-02 19:21 
GeneralRe: Thanks, but... Pin
devvvy28-Oct-02 19:24
devvvy28-Oct-02 19:24 
GeneralRe: Thanks, but... Pin
Shog928-Oct-02 19:29
sitebuilderShog928-Oct-02 19:29 
Generalyes, i've got it! Pin
devvvy28-Oct-02 19:31
devvvy28-Oct-02 19:31 
GeneralRe: Thanks, but... Pin
Maximilien29-Oct-02 2:22
Maximilien29-Oct-02 2:22 
Generaltaskbar Pin
devvvy28-Oct-02 17:13
devvvy28-Oct-02 17:13 
GeneralRe: taskbar Pin
Shog928-Oct-02 19:37
sitebuilderShog928-Oct-02 19:37 
Generaldraw on a button... Pin
devvvy28-Oct-02 15:34
devvvy28-Oct-02 15:34 
Generalpaint a bitmap on button... Pin
devvvy28-Oct-02 15:55
devvvy28-Oct-02 15:55 
GeneralRe: draw on a button... Pin
ian mariano29-Oct-02 1:43
ian mariano29-Oct-02 1:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.