C
cj
I wrote this code in a windows app and it works:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim ds As New DataSet
Dim myDbConnection As New OdbcConnection("Driver={Microsoft
Visual FoxPro Driver};" & _
"SourceType=DBF;" & _
"SourceDB=i:\probill\;" & _
"Exclusive=No;" & _
"Collate=Machine;" & _
"NULL=NO;" & _
"DELETED=NO;" & _
"BACKGROUNDFETCH=YES")
Dim mydbcommand As New OdbcCommand("select flag from act_frau
where act = '" + TextBox1.Text.Trim + "'", myDbConnection)
myDbConnection.Open()
Dim results As String = mydbcommand.ExecuteScalar()
myDbConnection.Close()
MessageBox.Show(results)
End Sub
So why doesn't this work:
<WebMethod()> _
Public Function CashOnly(ByVal act String) As String
Dim ds As New DataSet
Dim myOdbcConnection As New OdbcConnection("Driver={Microsoft
Visual FoxPro Driver};" + _
"SourceType=DBF;" + _
"SourceDB=i:\probill\;" + _
"Exclusive=No;" + _
"Collate=Machine;" + _
"NULL=NO;" + _
"DELETED=NO;" + _
"BACKGROUNDFETCH=YES")
Dim myOdbcCommand As New OdbcCommand("select flag from act_frau
where act = '" + act.Trim + "'", myOdbcConnection)
myOdbcConnection.Open()
Dim results As String = myOdbcCommand.ExecuteScalar()
myOdbcConnection.Close()
Return results
End Function
I get:
System.Data.Odbc.OdbcException: ERROR [42S02] [Microsoft][ODBC Visual
FoxPro Driver]File 'act_frau.dbf' does not exist.
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle,
RetCode retcode)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior
behavior, String method, Boolean needReader, Object[] methodArguments,
SQL_API odbcApiMethod)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior
behavior, String method, Boolean needReader)
at System.Data.Odbc.OdbcCommand.ExecuteScalar()
at TestWebService1.PaymentService1.CashOnly(String act) in
C:\Documents and Settings\cj\My Documents\Visual Studio
2008\Projects\TestWebService1\TestWebService1\PaymentService1.asmx.vb:line
47
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim ds As New DataSet
Dim myDbConnection As New OdbcConnection("Driver={Microsoft
Visual FoxPro Driver};" & _
"SourceType=DBF;" & _
"SourceDB=i:\probill\;" & _
"Exclusive=No;" & _
"Collate=Machine;" & _
"NULL=NO;" & _
"DELETED=NO;" & _
"BACKGROUNDFETCH=YES")
Dim mydbcommand As New OdbcCommand("select flag from act_frau
where act = '" + TextBox1.Text.Trim + "'", myDbConnection)
myDbConnection.Open()
Dim results As String = mydbcommand.ExecuteScalar()
myDbConnection.Close()
MessageBox.Show(results)
End Sub
So why doesn't this work:
<WebMethod()> _
Public Function CashOnly(ByVal act String) As String
Dim ds As New DataSet
Dim myOdbcConnection As New OdbcConnection("Driver={Microsoft
Visual FoxPro Driver};" + _
"SourceType=DBF;" + _
"SourceDB=i:\probill\;" + _
"Exclusive=No;" + _
"Collate=Machine;" + _
"NULL=NO;" + _
"DELETED=NO;" + _
"BACKGROUNDFETCH=YES")
Dim myOdbcCommand As New OdbcCommand("select flag from act_frau
where act = '" + act.Trim + "'", myOdbcConnection)
myOdbcConnection.Open()
Dim results As String = myOdbcCommand.ExecuteScalar()
myOdbcConnection.Close()
Return results
End Function
I get:
System.Data.Odbc.OdbcException: ERROR [42S02] [Microsoft][ODBC Visual
FoxPro Driver]File 'act_frau.dbf' does not exist.
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle,
RetCode retcode)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior
behavior, String method, Boolean needReader, Object[] methodArguments,
SQL_API odbcApiMethod)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior
behavior, String method, Boolean needReader)
at System.Data.Odbc.OdbcCommand.ExecuteScalar()
at TestWebService1.PaymentService1.CashOnly(String act) in
C:\Documents and Settings\cj\My Documents\Visual Studio
2008\Projects\TestWebService1\TestWebService1\PaymentService1.asmx.vb:line
47