Monday, March 15, 2010

Webservice String array value in C #

When we works with Webservice,we can't use the .NET data types like DataSet or DataTable,ArrayList as return value.
So we need to convert these into unified data type such as string or string array.

public string[] RecordAll()
SqlConnection con = new SqlConnection("Server=Your server\\SQLExpress;Database=SPTest; Trusted_Connection=Yes");
DataSet ds = new DataSet();
ArrayList al = new ArrayList();
SqlCommand cmd = new SqlCommand("Select * from Registers",con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds, "Registers");
foreach (DataRow row in ds.Tables[0].Rows)
string[] stringArray = (string[])al.ToArray(typeof(string));
return stringArray;