把数据库查询做成web service,包含有参数,
Imports System.Web.Services<WebService(Namespace:="http://tempuri.org/")> _
Public Class Service1
    Inherits System.Web.Services.WebService
      <WebMethod()> Public Function getshucai(ByVal keyword1 As String) As DataSet
        Dim ds As New DataSet()
        Dim strcon As String = "server=(local);database=kecheng;uid=sa;password=;"
        Dim objcon As New SqlClient.SqlConnection(strcon)
        Dim strsql As String
        strsql = "select * from shucai_index where title='" + keyword1 + "' "
        Dim objada As New SqlClient.SqlDataAdapter(strsql, objcon)
        objada.Fill(ds)
        Return ds
    End FunctionEnd Class然后做一个页面,用来引用web服务的,
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ws As New jianshuowebclient.localhost4.Service1()
        ws.Credentials = System.Net.CredentialCache.DefaultCredentials
       DataGrid1.DataSource = ws.getshucai(keyword.Text)
        DataGrid1.DataBind()
    End Sub其中的keyword是一个textbox控件,但把keyword.text传递给web service时老是出错,不知对于查询,参数应该如何使用??

解决方案 »

  1.   

    先判断一下返回的DATASET是否为NULL
      

  2.   

    IF ws.getshucai(keyword.Text)<> NULL
           DataGrid1.DataSource = ws.getshucai(keyword.Text).tables[0].defaultView
            DataGrid1.DataBind()
      

  3.   

    出现的错误提示是这样:请指点一下
    Ambiguous match found. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Reflection.AmbiguousMatchException: Ambiguous match found.Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
      

  4.   

    clxxj(chensir之.net外传)
    IF ws.getshucai(keyword.Text)<> NULL
    这个语句出错,提示改为system.dbnull也是不行,这语句有什么用,我的web service调试是可以用的,但在调用时就出现了上现的提示信息
      

  5.   

    你在.net框架帮助中查找AmbiguousMatchException这个异常的帮助就知道是什么问题了,不是你调用的方法错误,而是你的方法或变量等命名的问题,在调试模式下看看具体哪个命名产生混淆
      

  6.   

    如果应用程序调用了某个类但无法确定应使用哪个类或重载类,则引发 AmbiguousMatchException。绑定尝试定位要使用的适当的类,具体取决于参数个数和参数类型。如果定位了多个可接受的类,则引发 AmbiguousMatchException。
      

  7.   

    我还是不知怎么修改上面的程序,我做了一个简单的进行调试,也出现了同样的问题。
    <webmethod>public function abc(byval a as string,byval b as string) as string
    dim c as string
    c=a+b
    return c
    end function
    调用的程序如下
    dim ws as new webservice1.service1()            webservice1.service1是web服务的类名
    label1.text=ws.abc(label2.text,label3.text)
      

  8.   

    不太熟悉vb.net,从上面的代码中也看不出有什么名称不明确的地方,难道你在调试模式下运行时也显示不出来具体是哪一行出错了吗?
      

  9.   

    dim ws as new webservice1.service1()
    相当于实例化对象了没有呀?
      

  10.   

    问题已解决了,是因为我的页面上有一个textbox控件,命名为subject,跟里面的datagrid控件中绑定数据库的字段名subject一样,所以出错了