This is code of webservice function in vb working fine
` 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`
In Csharp i converted this vb coding..but not working.. i found some errors in converting string array into string.. near line 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 ;
}
This is my Csharp coding here i found errors in resultarray..last 4 lines shows some errors like no overload for method’Gettype’ and cannot implicitlyconvert type string to string[].
Change your code like below :
You can convert your code from Vb.Net to C# from below link :
http://www.developerfusion.com/tools/convert/vb-to-csharp/