Problem med webservice array
Hej Eksperter,Jeg har denne kode/webservice :
public struct DataHolder
{
public String Name;
public Int Id;
public String Content;
}
[WebMethod]
public DataHolder[] GetData(string Id)
{
DataHolder[] DataElm= null;
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnect"].ConnectionString);
SqlCommand command = new SqlCommand("GetData", myConnection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@Id", SqlDbType.VarChar);
command.Parameters["@Id"].Value = @CallInId;
command.Connection.Open();
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
int x = 1;
if(reader.HasRows){
while(reader.Read()){
DataElm= new DataHolder[x];
DataElm[x].Name = reader["Name"].ToString();
DataElm[x].Id= reader["Id"].ToString();
DataElm[x].Content= reader["Content"].ToString();
x++;
}
}
command.Connection.Close();
return DataElm;
}
men jeg får en "System.IndexOutOfRangeException: Index was outside the bounds of the array.
" fejl i alle disse linjer :
DataElm[x].Name = reader["Name"].ToString();
DataElm[x].Id= reader["Id"].ToString();
DataElm[x].Content= reader["Content"].ToString();
Er der nogle der kan se hvad fejlen er !