Hi people, may i know how can i retrieve data from database(linq to sql) using webclient and display in listbox? I realied most of the articles talk about creating xml file and use XDocument or XElement. Is there any possibility that i can consume the web service and retrieve the data?
Urgent. People please help me :(
Loading

Pravin MoreRank #1,419 · 1.2K reputationPosted Nov 17, 2011, 6:45 PM EST
you can return List
i.e. return type of service will be List
Sarah8 reputationPosted Nov 17, 2011, 8:05 PM EST
this is how my codings in xaml.cs look like:
public Details { InitializeComponent();WebClient proxy = new WebClient(); string baseUri = "http://localhost:1723/ServiceImpl.svc/GetDetails"; proxy.DownloadStringCompleted += new DownloadStringCompletedEventHandler(proxy_DownloadStringCompleted); proxy.DownloadStringAsync(new Uri(baseUri)); } void proxy_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) { return; } if (e.Result == null) MessageBox.Show("NUlllllllllll"); XDocument xmlCurrent = XDocument.Parse(e.Result); ListBox.DataContext = xmlCurrent; }Pravin MoreRank #1,419 · 1.2K reputationPosted Nov 17, 2011, 9:03 PM EST
ok then you can add it by foreach.......
try like this...
foreach(string str in e.result)
{
listBox1.Add(str);
}
note:- i hope you can do any typecast or to list if required.
let me know if works or not.
Thanks,
Pravin.
Sarah8 reputationPosted Nov 18, 2011, 10:20 PM EST
the codes doesnt work well.
error for foreach: Cannot convert type 'char' to 'string'.
error for ListBox.Add(str); : Error 1 'System.Windows.Controls.ListBox' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.Windows.Controls.ListBox' could be found (are you missing a using directive or an assembly reference?)
Prabhu RajaRank #861 · 2.6K reputationPosted Nov 19, 2011, 2:21 AM EST
foreach(char str in e.result)
{
listBox1.Items.Add(str.ToString());
}
Sarah8 reputationPosted Nov 19, 2011, 6:07 AM EST