【发布时间】:2011-12-13 23:36:05
【问题描述】:
这是在 vb 中的 webservice 功能代码工作正常
` Public Function GetProducts(ByVal prefixText As String, _
ByVal count As Integer) As String()
Dim SelectQry = "select * from employee where Ename like '" & prefixText & "%'"
Dim Results As New ArrayList
Try
Using Command As New SqlCommand(SelectQry, Connection)
Using Reader As SqlDataReader = Command.ExecuteReader()
Dim Counter As Integer
While Reader.Read
If (Counter = count) Then Exit While
Results.Add(Reader("Ename").ToString())
Counter += 1
End While
End Using
Dim ResultsArray(Results.Count - 1) As String
ResultsArray = Results.ToArray(GetType(System.String))
Return ResultsArray
End Using
Catch ex As Exception
Throw ex
End Try
End Function`
在 Csharp 中,我转换了这个 vb 编码..但没有工作..我发现将字符串数组转换为字符串时出现了一些错误..近线 resultsarray(results.count-1)
[WebMethod]
public string[] GetProducts(string prefixText,int count)
{
SqlConnection con = new
SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\WebSite3\\App_Data\\Country.mdf;Integrated Security=True;User Instance=True");
con.Open();
ArrayList results = new ArrayList();
string strQuery = "select * from employee where Ename like '" + prefixText + "%'";
SqlCommand cmd = new SqlCommand(strQuery, con);
SqlDataReader dr = cmd.ExecuteReader();
int Counter;
while (dr.Read())
{
if (Counter == count)
break;
results.Add(dr["Ename"].ToString());
Counter++;
}
string resultsarray;
resultsarray(results .count -1);
resultsarray =results.ToArray (GetType (System.String ));
return resultsarray ;
}
这是我的 Csharp 编码,我在 resultarray 中发现了错误。最后 4 行显示了一些错误,例如方法“Gettype”没有重载,并且无法将类型字符串隐式转换为字符串 []。
【问题讨论】:
-
这不是一个编码服务,也许将你自己的c#代码粘贴到特定的错误中,你可能会得到一些帮助。
标签: c# web-services autocomplete