把数据库查询做成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时老是出错,不知对于查询,参数应该如何使用??
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时老是出错,不知对于查询,参数应该如何使用??
DataGrid1.DataSource = ws.getshucai(keyword.Text).tables[0].defaultView
DataGrid1.DataBind()
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.
IF ws.getshucai(keyword.Text)<> NULL
这个语句出错,提示改为system.dbnull也是不行,这语句有什么用,我的web service调试是可以用的,但在调用时就出现了上现的提示信息
<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)
相当于实例化对象了没有呀?