我正在尝试从webservice检索活动数据。这是我的网络服务代码。
public string getRecentActivity(string userName)
{
string result1 = "";
string result2 = "";
string result3 = "";
string result4 = "";
string result5 = "";
string sql = "EXEC GetRecentActivities '" + userName + "'";
SqlCommand cmd = new SqlCommand(sql, sqlConnection);
SqlDataReader reader;
try
{
sqlConnection.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
result1 += reader[0] + "#";
result2 += reader[1] + "#";
result3 += reader[2] + "#";
result4 += reader[3] + "#";
result5 += reader[4] + "#";
}
}
catch (Exception) { }
return result1 + "~" + result2 + "~" + result3 + "~" + result4 + "~" + result5;
}
我的Windows Mobile有以下XAML文件。
<ListBox Grid.Row="1" Height="Auto" HorizontalAlignment="Left" Margin="12,140,0,0" Name="lb_AllActivity" VerticalAlignment="Top" Width="Auto" FontFamily="Tahoma" FontSize="25">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Border Margin="3">
<StackPanel Background="Transparent" Orientation="Vertical" Width="420" Height="60">
<StackPanel Background="Transparent" Orientation="Horizontal" Width="420" Height="60">
<TextBlock Foreground="White" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" Text="{Binding DateTime}"></TextBlock>
<TextBlock Foreground="White" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" Text="{Binding Amt}"></TextBlock>
<TextBlock Foreground="White" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" Text="{Binding Msg}"></TextBlock>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
至于CS文件,我有以下代码: 我的CS FIle中有以下代码
public partial class Activities : PhoneApplicationPage
{
DatabaseService.ServiceSoapClient dbService = new DatabaseService.ServiceSoapClient();
public Activities()
{
InitializeComponent();
InitializeComponent();
dbService.getAllActivityAsync("Russell Loh");
dbService.getAllActivityCompleted += new EventHandler<DatabaseService.getAllActivityCompletedEventArgs>(dbService_getAllActivity);
}
public class AllActivity
{
public string TransID { get; set; }
public string Amt { get; set; }
public string Cat { get; set; }
public string SharedNo { get; set; }
public string Msg { get; set; }
public string DateTime { get; set; }
}
void dbService_getAllActivity(object sender, DatabaseService.getAllActivityCompletedEventArgs e)
{
if (e.Error == null)
{
string result = e.Result;
string[] arrayActivity = result.Split('~');
string[] transID = arrayActivity[0].Split('#');
string[] amount = arrayActivity[1].Split('#');
string[] category = arrayActivity[2].Split('#');
string[] sharedNum = arrayActivity[3].Split('#');
string[] message = arrayActivity[4].Split('#');
string[] dateTime = arrayActivity[5].Split('#');
List<String> Activitylist = new List<String>();
for (int i = 0; i < transID.Length; i++)
{
string TransID = transID[i];
string Amt = amount[i];
string Cat = category[i];
string SharedNo = sharedNum[i];
string Msg = message[i];
string DateTime = dateTime[i];
//create a new instance of activity
AllActivity activity = new AllActivity();
activity.Amt = Amt;
activity.Msg = Msg;
activity.DateTime = DateTime;
Activitylist.Add(activity);
}
lb_AllActivity.ItemsSource = Activitylist;
}
}
但是,我遇到以下错误:Activitylist.Add(activity); “System.Collections.Generic.List”的最佳重载匹配包含一些无效参数。
有人可以告诉我这个错误。我该怎么做才能解决这个错误。 谢谢
答案 0 :(得分:1)
您已将活动列表声明为字符串列表,它应该是AllActivity列表
List<String> Activitylist = new List<String>();
应该是
List<AllActivity> Activitylist = new List<AllActivity>();