将输入发送到 web 服务时,我遇到了一些问题。
这是我的代码:
Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Saman.Click
SamanDB.DataSource = Nothing
SamanDB.DataBind()
Dim str As String
str = TextBox1.Text
>> Dim copsdataXML As String = myCOPSWeb.Summon(str)
Dim dsReader As StringReader = New StringReader(copsdataXML)
Dim DS As DataSet = New DataSet()
DS.ReadXml(dsReader)
SamanDB.DataSource = DS
SamanDB.DataBind()
End Sub
这里是网络服务:-
public string Summon(string Input1)
{
SqlDataAdapter dbadapter = null;
DataSet returnDS = new DataSet();
using (SqlConnection dbconn = new SqlConnection(
"Server=11.2.6.10;"
+ "Database=POLIS;"
+ "User ID=*******;"
+ "Password=*******;"
+ "Trusted_Connection=False;"))
{
SqlCommand cmd = new SqlCommand();
string sqlQuery = "select * from SUMMON where ic_no=@Input1";
cmd.CommandText = sqlQuery;
cmd.Connection = dbconn;
dbadapter = new SqlDataAdapter(cmd);
cmd.Parameters.Add("@Input1", SqlDbType.VarChar).Value = Input1;
dbadapter.Fill(returnDS);
}
return returnDS.GetXml();
}
我想将 TextBox1.Text 作为 Input1 发送到 web 服务。这是我得到的例外:-
用户代码未处理 SoapException。
System.Web.Services.Protocols.SoapException:服务器无法处理请求。---> System.Data.SqlClient.SqlException: Parameterized Query '(@Input1 varchar(8000))select * from SUMMON where ic_no=@Input1' 需要参数@Input1,但未提供。