本文介绍了返回Web服务中的数据库查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在Windows应用程序中编写了这段代码并且它可以工作: Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System .EventArgs)处理Button1.Click Dim ds作为新数据集 将myDbConnection调暗为新的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(从act_frau中选择标志 where act =''" + TextBox1.Text.Trim +"''", myDbConnection) myDbConnection.Open() Dim results As String = mydbcommand.ExecuteScalar() myDbConnection.Close() MessageBox.Show(results) End Sub 那么为什么这不起作用: < WebMethod()_ 公共函数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:\ probbill \;" + _ " Exclusive = No;" + _ " Collate = Machine;" + _ " NULL = NO;" + _ " DELETED = NO;" + _ " BACKGROUNDFETCH = YES") Dim myOdbcCommand As New OdbcCommand(从act_frau中选择标志 where act =''" + act.Trim +"''",myOdbcConnection) myOdbcConnection.Open() Dim results As String = myOdbcCommand.ExecuteScalar() myOdbcConnection.Close() 返回结果 结束功能 我得到: System.Data.Odbc.OdbcException:ERROR [42S02] [Microsoft] [ODBC Visual FoxPro驱动程序]文件' 'act_frau.dbf''不存在。 at System.Data.Odbc.OdbcConnection.HandleError(OdbcHa ndle hrHandle, RetCode retcode) at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehavior behavior,String method,Boolean needReader,Object [] methodArguments, SQL_API odbcApiMethod) 在System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehavior 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 \ Paym entService1.asmx .vb:line 47 解决方案 2008年6月24日星期二14:37:56 -0400,cj< cj@nospam.nospamwrote: $ b $b¤为什么这不起作用: $ b $b¤ $ b $b¤< WebMethod()_ $ b $b¤公共功能CashOnly(ByVal act String)As String $ b $b¤Dim ds作为新数据集 $ b $b¤将myOdbcConnection调暗为新的OdbcConnection(Driver = {Microsoft $ b $b¤VisualFoxPro Driver};" + _ $ b $b¤" SourceType = DBF;" + _ $ b $b¤SourceDB = i:\ probbill \;" + _ $ b $b¤" Exclusive = No;" + _ $ b $b¤" Collate = Machine;" + _ $ b $b¤" NULL = NO;" + _ $ b $b¤" DELETED = NO;" + _ $ b $b¤" BACKGROUNDFETCH = YES") $ b $b¤ $ b $b¤将myOdbc命令调暗为新的OdbcCommand(从act_frau中选择标志 $ b $b¤其中act =''" + act.Trim +"''",myOdbcConnection) $ b $b¤ $ b $b¤myOdbcConnection.Open( ) $ b $b¤昏暗的结果As String = myOdbcCommand.ExecuteScalar() $ b $b¤myOdbcConnection.Close() $ b $b¤ ¤返回结果 $ b $b¤结束功能 $ b $b¤ $ b $b¤我得到: $ b $b¤ $ b $b¤System.Data.Odbc.OdbcException:错误[42S02] [Microsoft] [ODBC Visual $ b $b¤FoxPro驱动程序]文件''act_frau.dbf''不存在。在System.Data.Odbc.Odbc.OdbcCommand的System.Data.Odbc.OdbcConnection.HandleError(OdbcHa ndle hrHandle, $ b $b¤RetCoderetcode)上$ b $b¤ $ b $b¤。 ExecuteReaderObject(C ommandBehavior $ b $b¤行为,String me thod,Boolean needReader,Object [] methodArguments,ehavior,String method,Boolean needReader) $ b $b¤at System.Data.Odbc.OdbcCommand.ExecuteScalar() $ b $b¤在TestWebService1.PaymentService1.CashOnly(String act ) $ b $b¤C:\文档和设置\cj \ Myy文件\ Visual Studio $ b $b¤47 i驱动器在哪里?这是一个映射到网络资源的驱动器号,还是一个本地驱动器? Web服务器? Paul ~~~~ Microsoft MVP(Visual Basic) I wrote this code in a windows app and it works:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.ClickDim ds As New DataSetDim myDbConnection As New OdbcConnection("Driver={MicrosoftVisual 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_frauwhere act = ''" + TextBox1.Text.Trim + "''", myDbConnection)myDbConnection.Open()Dim results As String = mydbcommand.ExecuteScalar()myDbConnection.Close()MessageBox.Show(results)End SubSo why doesn''t this work:<WebMethod()_Public Function CashOnly(ByVal act String) As StringDim ds As New DataSetDim myOdbcConnection As New OdbcConnection("Driver={MicrosoftVisual 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_frauwhere act = ''" + act.Trim + "''", myOdbcConnection)myOdbcConnection.Open()Dim results As String = myOdbcCommand.ExecuteScalar()myOdbcConnection.Close()Return resultsEnd FunctionI get:System.Data.Odbc.OdbcException: ERROR [42S02] [Microsoft][ODBC VisualFoxPro Driver]File ''act_frau.dbf'' does not exist.at System.Data.Odbc.OdbcConnection.HandleError(OdbcHa ndle hrHandle,RetCode retcode)at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehaviorbehavior, String method, Boolean needReader, Object[] methodArguments,SQL_API odbcApiMethod)at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehaviorbehavior, String method, Boolean needReader)at System.Data.Odbc.OdbcCommand.ExecuteScalar()at TestWebService1.PaymentService1.CashOnly(String act) inC:\Documents and Settings\cj\My Documents\Visual Studio2008\Projects\TestWebService1\TestWebService1\Paym entService1.asmx.vb:line47 解决方案 这篇关于返回Web服务中的数据库查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!